More methods, more solutions question


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?


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


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} "


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