I’ve always liked the fact that nil evaluates to false. This is handy in conditional expressions and makes ||= possible.
However, something I didn’t expect is a bit annoying:
nil.to_i gives you a 0, which evaluates to true in ruby.
So stuff like this happens:
irb(main):002:0> puts "hello" if nil.to_i hello => nil
At a first glance, it seems like zero might have been better replaced by nil or an exception.
Does anyone have any insight as to why nil.to_i returns zero and why that might be more useful or better than an alternative solution?