> Is there a better way to test if a variable|instance is empty ?
> I usually use :
>
> @name = 'Guest' if @name.empty?


I generally use something like

    @name = (@name.nil? || @name.empty?) ? 'Guest' : @name

Is that objectively better? Not really.


I confess that in one (Sinatra) application here I have monkey-patched to give something similar to Rails' presence(), so I can just say

    @name = 'Guest' if @name.blank?

...because nil.blank? -> true (also "   ".blank?, [nil].blank?, ... but I digress.)


Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>