From: Sean O'Dell Date: 2004-06-15T07:59:11+09:00 Subject: Re: undefine On Monday 14 June 2004 15:47, Mark Hubbart wrote: > On Jun 14, 2004, at 2:58 PM, tony summerfelt wrote: > > while() > > { > > # date parsing code was here > > @diff=Delta_DHMS(@binkdate,@today) if /(\[\d+\])/; > > print $trimmed $_ if $diff[0] < $ARGV[1] && defined(@diff); > > next if defined(@diff); > > print $trimmed $_ if ! /(\[\d+\])/; > > undef(@diff); > > } > > testing whether diff is defined won't work in ruby anyway. Any time you > have an expression like this: > > foo = 23 if expression > > foo ends up being automagically defined anyway. After running that > code, if expression is false, foo == nil. > > So, as Sean says, it would probably be better to use nil, unless > Delta_DHMS might return nil itself. Oh! Which brings to mind something really neat I figured out awhile ago. If Delta_DHMS really can return nil as a valid value, try re-writing the code like this: { # date parsing code was here @diff=Delta_DHMS(@binkdate,@today) if /(\[\d+\])/; print $trimmed $_ if $diff[0] < $ARGV[1] && @diff != :undefined; next if @diff != :undefined; print $trimmed $_ if ! /(\[\d+\])/; @diff = :undefined; } Initialize @diff = :undefined in your class initialize method. :undefined will be a Ruby symbol that gets created on its first use. From there on out, just set @diff to :undefined whenever you need to "undefine" it. Sean O'Dell