It always helps if you include the error. There are two ways to fix that error:
- Interpolate the value:
puts "you would like #{number} much better"
- Turn it from a number to a string:
puts "you would like " + number.to_s + 'much better'
The former, #{...}
syntax, evaluates the content of the braces as Ruby, and then applies to_s
to the result, before injecting it into the string. My two examples are literally equivalent.
As to why it fails? +
doesn’t do type coercion in Ruby, which actually has very little implicit conversion going on, unlike other languages in similar spaces.
solved Very Basic Ruby puts and gets