What's wrong with this method

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 “/”

equinox [email protected] wrote:

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.

equinox wrote:

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)! :slight_smile:

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

On Nov 24, 10:52 am, Lee G. [email protected] wrote:

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

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

Posted viahttp://www.ruby-forum.com/.

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

equinox wrote:

On Nov 24, 10:52�am, Lee G. [email protected] wrote:

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

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

Posted viahttp://www.ruby-forum.com/.

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/

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?