I’d ask you why the following code doesn’t works:
data = gets
data.chomp
if data == “a”
puts “True”
else
puts “False”
end
It’s always false. (ruby 1.8.4 in WinXP console)
Thanks for your answers.
data = gets
data.chomp
It’s always false. (ruby 1.8.4 in WinXP console)
Thanks for your answers.
Michal wrote:
–
It’s always false. (ruby 1.8.4 in WinXP console)
“chomp” does not alter the string, it returns a new, modified copy.
“chomp!” does modify the string, and returns nil if no change was
made.
Try these instead:
data = gets.chomp
or:
data = gets
data.chomp!
Cheers,
Dave
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs