15. More Methods, more Solutions


Hello community,

I’m a little bit confused by the last module in Hashes and Symbols, more More Methods, more Solutions.

Here’s the example code

my_hash = { one: 1, two: 2, three: 3 }

my_hash.each_key { |k| print k, " " }
# ==> one two three

my_hash.each_value { |v| print v, " " }
# ==> 1 2 3

In the example code I don’t understand the purpose of the ," " after print k. Why is it there and what does it do?

I ran my code with it and got the error “wrong number of arguments”.

While my code worked perfectly without it.

Thanks in advance for any help :+1:


If you examine the output we see it is on one line. That’s what the comma is for in the print statement, The draw pencil holds the next position to what what last printed. We arbitrarily insert a space character after each print so the outputs are not all scrunched together like,



Thanks. Very helpful as always:slightly_smiling_face:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.