From: Florian Frank Date: 2005-05-07T06:54:27+09:00 Subject: Re: RCR 303: nil should accept missing methods and return nil John Carter wrote: > A very simple and generic way of improving the reliability of Ruby > programs is to implement the NullObject pattern by allowing nil to > accept all and every method instead of throwing a NoMethodError. Great! I've so long waited for something like this. I have just written a very reliable program, with this new feature: class NilClass def method_missing(*ignore) nil end end class Counter def initialize @count = 1 end attr_reader :count def increase @count += 1 end end class DoSomething def initialize @coutner = Counter.new end def count_done @counter.count end def do_it @counter.increase end end ds = DoSomething.new 10.times do ds.do_it end puts "Have done it #{ds.count_done} times." -- Florian Frank