what's wrong with this method

P

Patrick Doyle

[Note: parts of this message were removed to make it a legal post.]

What is the "to_out" method supposed to do? Is it supposed to return a
string, or print stuff to stdout? The first line of code creates a string
filled all sorts of interesting information about your object (username,
name, sex, ...). The second line calls #puts some number of times depending
on how many elements are in the @friends hash.

--wpd
 
L

Lee Griffiths

equinox said:
can someone tell me what's wrong with this method??

http://pastie.org/322677

after that FRIENDS I print I want to iterate over the hash that I have
and print the key, value of each separated by a "/"


You have a syntax error, for a start. Is this the problem you mean?

@friends.each do {|key, value| puts("#{key}/#{value} ,") }

It's EITHER { } OR do...end. Not both (or half of one)! :)
 
M

matt neuburg

equinox said:
can someone tell me what's wrong with this method??

http://pastie.org/322677

after that FRIENDS I print I want to iterate over the hash that I have
and print the key, value of each separated by a "/"

Your pastie consists of a two-line method definition, to_out().

The first line of to_out() is valid but does nothing; it defines a
literal string whose value is then thrown away.

The second line will not compile because it tries to combine the "do"
form of a block with the curly-braces ({}) form of a block. Pick one or
the other. For example, delete "do".

The second line will then work (well, it will do *something*, though
what it does is pretty weird-looking) provided you have a @friends hash.
There is no indication in your pastie to tell whether you do or you
don't.

m.
 
E

equinox

You have a syntax error, for a start. Is this the problem you mean?

@friends.each do {|key, value| puts("#{key}/#{value} ,") }

It's EITHER { } OR do...end. Not both (or half of one)! :)

I just want it to return a string.. and for the second line I want to
get the string from the key value pair in the hash
 
L

Lee Griffiths

equinox said:
I just want it to return a string.. and for the second line I want to
get the string from the key value pair in the hash

Only the _LAST_ statement in a function is the return value. So put that
string second after you've done a puts. If you haven't alread done so,
give this a read: http://www.rubycentral.com/book/
 
M

Mark Thomas

I just want it to return a string.. and for the second line I want to
get the string from the key value pair in the hash

That's exactly what they gave you. Did you try it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,832
Latest member
UtaHetrick

Latest Threads

Top