7/8 ...yes, but WHY do we .to_s


I get what .to_s does, but I output the same result with:
frequencies.each {|w,f| puts "#{w}: #{f}"}

Why is there a need to convert an integer into a string?
(or is this done solely to show that a number can be converted into a string?)


Note that we must first convert the value from a number to a string using .to_s before we can concatenate it.
so if you did not convert it to a string, it will not concatenate. because concatenate only apply to a string.


Megablaster used string interpolation so there is no need to convert to a string. The lesson used a different way of doing this, concatenate which is why the value must first be converted first to a string .to_s

Megablaster I'm assuming is a little more advanced so is using interpolation which hasn't been taught yet. I personally find interpolation easier but codecademy hasn't covered that topic yet which is why in this tutorial they've concatenated it which is why it needs to be converted .to_s


@jaydacoder I appreciate the faith my skill, but I was really just stumbling about with the code and it worked... I think they used this in an earlier lesson that's where I pulled it from. Thanks for explaining Interpolation / concatenation. I wouldn't have understood a month ago, but now I know what you're talking about :slight_smile: