Jump to content


Check out our Community Blogs

serpent

Member Since 01 May 2012
Offline Last Active Jul 07 2016 10:42 AM
-----

#632405 Empty Input Doesn't Equal Nil?

Posted by serpent on 26 June 2012 - 12:14 AM

Your code does not work because gets.chomp does not return nil.
When user just presses the enter key gets returns "\n", so gets.chomp will remove end of line char leaving empty string.

This evaluates to true
input = gets.chomp
puts (input == '')

This is also correct
input = gets.chomp
puts (input.empty?)

  • 1