From: Daniel DeLorme Date: 2007-06-24T12:42:46+09:00 Subject: Re: avoiding nil.methodcalls short and cheap Trans wrote: > Interesting... I like this. Nice use of fluent / magic dot notation. > This is a good use case for Functor too (see Facets): > > class NilClass > def ergo > @blackhole ||= Functor.new{ nil } > @blackhole unless block_given? > end > end Indeed, that really simplifies the code. > One question, I'm not sure what you expect to be returned if a block > is given. foo.ergo{ |o| o.bar } #=> result of bar nil.ergo{ |o| o.bar } #=> nil because sometimes some cases don't lend themselves very well to "magic dot" notation. > Besides that one issue, I'd like to add this to Facets and credit you. By all means, I'd be honored. Daniel