From: "David A. Black" Date: 2009-02-22T03:39:09+09:00 Subject: Re: why not check for nil? Hi -- matt neuburg wrote: > Roger Pack wrote: > >> matt neuburg wrote: >>> A post I ran across on a rails forum reads: >>> >>> "Warning! DO NOT test for nil! This is a very bad coding practice. You >>> can use "if obj", but do not use "if obj.nil?" or whatever." >>> >>> Is that generally true? Why? m. >> because it might be false [not nil]? > > Yes, I thought of that too. But of course to me that is *why* I would > check for nil (I really really do want to know if it's nil). Definitely use #nil? if you want to know whether something is exactly nil. There are certainly a lot of unnecessary calls to #nil? out there, but it doesn't follow that it can never be right to test for nil. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) Ruby Training Atlanta! April 1-3, http://www.entp.com/training/atlanta09