From: Xavier Noria Date: 2008-07-24T16:09:19+09:00 Subject: Re: differnce between .nil? , .empty?, .blank? On Thu, Jul 24, 2008 at 9:00 AM, Sijo Kg wrote: > Could you please tell me when to use .nil? , .empty?, .blank? .What > are the difference between them.. For example I have > params[:company][:whichCompany] > And to check for it is null I first attempted all these and finally the > following worked > if !params[:company][:whichCompany].empty? > > So now really i am confused .Please tell me the differnce nil? tests whether the object is exactly nil, that is whether it is the one and only want instance of NilClass. empty? is a method some objects respond to. You need to check the documentation for each case. For example, and empty array is one that is not nil (it is an array right?) and has no elements. An empty string is one that is not nil (it is a string right?) and has no bytes, nothing. The blank? method you ask for does not belong to Ruby, it is a Rails extension: http://api.rubyonrails.com/classes/Object.html#M000011.