What's wrong with this method


#1

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


#2

equinox removed_email_address@domain.invalid 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.


#3

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:


#4

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


#5

On Nov 24, 10:52 am, Lee G. removed_email_address@domain.invalid 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


#6

equinox wrote:

On Nov 24, 10:52�am, Lee G. removed_email_address@domain.invalid 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/


#7

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?