Newbee Dev Newbee Dev - 1 year ago 78
Ruby Question

condition to input value always return false (RUBY)

I wonder why even though I type "y" the condition will always false

puts "Would you like to continue [y/n]"
confirm = gets
puts confirm == "y" # why this is not true even I type "y"

if confirm == "y"
puts "Input is y"

Answer Source

Try use confirm = gets.chomp cause gets set what you enter with \n in the end

> a = gets
> y
 => "y\n"