hellogoodbye hellogoodbye - 1 year ago 112
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

Answer Source

Like this:

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