Write as below :
if x < y
puts "#{x} is less than #{y}"
elsif x > y
puts "#{x} is greater than #{y}"
else
puts "#{x} is equal to #{y}"
end
"x"
create a new string and not treated as the number you took from the console. But when you are write "#{x}"
, it is giving the number, but in string format using interpolation.
When you would write "x" > "y"
, you are checking/testing those string literals 'x' and 'y' by their lexicographical ordering, but x > y
is the comparisons of the two numbers you took from the console using gets.to_i
.