More methods, more solutions question


#1



Dear community,

Could someone please explain to me the difference between the below two lines of code and why the exercise only approves of one of the two?

Thanks


https://www.codecademy.com/en/courses/ruby-beginner-en-Qn7Qw/2/5?curriculum_id=5059f8619189a5000201fbcb


movie_ratings.each_key { |k| puts k, " " }
movie_ratings.each_key { |k| puts "#{k} " }


#2

puts k, " " and puts "#{k} " have different outputs. First one will print k variable, then in a new line it will print " " which is just another empty line. Second one will print variable k in a line.
If you want same effects, either choose between puts k and puts "#{k}"
Or if you really want that " " - space which is pointless in case of using puts - puts k.to_s + " " and puts "#{k} "


#3

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