hellogoodbye hellogoodbye - 6 months ago 14
Ruby Question

ruby apply method to string interpolation

I want to convert a neg number to a pos in ruby so am using the abs method.

puts("You are #{playerGuess - num} away")


this is the current code but want to make the result from playerGuess - num always positive. how does one apply the abs method to this? if I do
#{playerGuess - num}
it just outputs the word
abs

Answer

Like this:

puts("You are #{(playerGuess - num).abs} away")