Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Very often I find code that uses the method nil? to determine whether a certain value is equal to nil. Writing expr.nil?, however, performs a method call in the Ruby interpreter. This is somewhat stupid of Ruby, as it is not possible to redefine nil? in any way, and the compiler could easily optimize this on the fly.
If you know that the value tested is not a Boolean, you can usually eliminate the method call. For example, you can transform