On Tue, 22 Feb 2005 00:27:59 +0900, Bill Kelly <billk / cts.com> wrote:
> From: "Christian Neukirchen" <chneukirchen / gmail.com>
> >
> > Sometimes, I'd like an "eating nil" that returns itself for each
> > method call, and is false.
> >
> > Then, stuff like that would be possible
> >
> > while line = gets.ignore_if_nil.chomp
> >   ...
> > end
> >
> > Maybe just a crazy idea... :-)
> 
> class NilClass
>   def method_missing(meth_id, *args); self; end
> end
> 
> ?
> 
> :)
> 
> ObjectiveC's nil works this way.
> 
> The downside is you don't find out as early when you
> received an unexpected nil, in situations where you
> would have preferred to be notified.
> 
> Regards,
> 
> Bill
> 
> 

Ooo, this just gave me an idea!

Block scope redefinitions of classes!

withImaginaryHungryNilConstruct do
         while(line = gets.chomp )
              # do stuff with line
         end
end # here NilClasses's definition reverts back to normal

You could do this in Ruby now, the only problem being is it would have
dynamic and not lexical "scope" if I may obscenely misuse a term. This
could be quite useful, I imagine, especially if it was generic (eg.
have a way of saying use these modifications for class X for the
duration of this block).