[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Combine @item.foo.nil? || @item.foo.empty? ?

Gavin Kistner

9/8/2006 8:54:00 PM

> unless (@item.foo.nil? || @item.foo.empty?)
> Is there a way to combine these two OR clauses into one?

You could always modify nil so that empty? worked for it:

irb(main):001:0> a = nil
=> nil
irb(main):002:0> a.nil?
=> true
irb(main):003:0> a.empty?
NoMethodError: undefined method `empty?' for nil:NilClass
from (irb):3
irb(main):004:0> class NilClass; def empty?; true; end; end
=> nil
irb(main):005:0> a.empty?
=> true