This community-built FAQ covers the “More Methods, More Solutions” exercise from the lesson “Hashes and Symbols”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Learn Ruby
FAQs on the exercise More Methods, More Solutions
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (
) below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply (
) below!
Agree with a comment or answer? Like (
) to up-vote the contribution!
Need broader help or resources? Head here.
Looking for motivation to keep learning? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account or billing? Reach out to our customer support team!
None of the above? Find out where to ask other questions here!
Hi!
I understand that .each_key and .each_value allow me to iterate over only the key or value of a hash but in the code
my_hash.each_value { |v| print v, " " }
I dont understand the point of , " " , its a string with a space?
Thanks for your time
2 Likes
Yes the " " is simply a string with a space. Because you are using print, the " " allows you to separate each value with a space instead of squishing them altogether. To show this clearly we can use something other than a space.
my_hash = {
"one" => 1,
"two" => 2,
"three" => 3
}
my_hash.each_value { |v| print v, "INBETWEEN" }
This prints
1INBETWEEN2INBETWEEN3INBETWEEN
1 Like
Hi guys. Can you tell me what I’m doing wrong?
movie_ratings = {
memento: 3,
primer: 3.5,
the_matrix: 3,
truman_show: 4,
red_dawn: 1.5,
skyfall: 4,
alex_cross: 2,
uhf: 1,
lion_king: 3.5
}
movie_ratings.each_key { |k| puts k, " "}
gives an error
wrong number of arguments (given 2, expected 1)
I checked through repl.it and my code works
Oh, I realized I shouldn’t have used " "
Hi need help with this question
movie_ratings = {
memento: 3,
primer: 3.5,
the_matrix: 3,
truman_show: 4,
red_dawn: 1.5,
skyfall: 4,
alex_cross: 2,
uhf: 1,
lion_king: 3.5
}
my_hash = { one: 1, two: 2, three: 3 }
my_hash.each_key { |k| print k, " " }
my_hash.each_value { |v| print v, " " }
no matter what i try nothing works
Sorry figured it out
movie_ratings = {
memento: 3,
primer: 3.5,
the_matrix: 3,
truman_show: 4,
red_dawn: 1.5,
skyfall: 4,
alex_cross: 2,
uhf: 1,
lion_king: 3.5
}
Add your code below!
movie_ratings.each do |x,y|
puts x
end
Hi! As far as I understand the program wants you to use puts instead of print. And with puts you do not need to use extra space like " ".
my code was only:
movie_ratings.each_key { |k| puts k}