J
Joe Johnson
Hi, can someone please explain why the line
puts "YES" if x == 0 returns nil? Does ruby
convert x to a fixnum or convert 0 to a string?
Either case, shouldn't it return TRUE, since the
== operator works for both fixnum and string?
TIA!
irb(main):001:0> x="0"
=> "0"
irb(main):002:0> puts "YES" if x == "0"
YES
=> nil
irb(main):003:0> puts "YES" if x == 0 # CONFUSED LINE
=> nil
puts "YES" if x == 0 returns nil? Does ruby
convert x to a fixnum or convert 0 to a string?
Either case, shouldn't it return TRUE, since the
== operator works for both fixnum and string?
TIA!
irb(main):001:0> x="0"
=> "0"
irb(main):002:0> puts "YES" if x == "0"
YES
=> nil
irb(main):003:0> puts "YES" if x == 0 # CONFUSED LINE
=> nil