Cyent wrote:
>
> Anybody who is vaguely worried about bugs in their code whether they are
> running perl or ruby should _always_ use the -w switch.

So your argument is that because this particular error appeared when 
using the -w switch, it is just fine that the NullObject pattern 
completely hid it?

Sorry, I don't buy it. In fact, this has shades of a Straw Man to me.

How about this:

class NilClass
   def method_missing(*ignore) nil end
end

$counters = []

class Counter
   def initialize(name)
     @name = name
     @count = 1
   end

   attr_reader :count, :name

   def increase
     @count += 1
   end

   def ==(other)
     @name = other.name
   end
end

def counter_factory(name)
   c = Counter.new(name)
   if not $counters.include? c
     $counters << c
     c
   end
end

class DoSomething
   def initialize
     @name = 'DS'
     @counter = counter_factory(@name)
   end

   def count_done
     @counter.count
   end

   def do_it
     @counter.increase
     if @counter.count > 5
       @counter = counter_factory(@name)
     end
   end
end

ds = DoSomething.new
10.times do
   ds.do_it
end
puts "Have done it #{ds.count_done} times."
__END__

Contrived? Maybe. But it doesn't have warnings and it doesn't work like 
it should, all because of a small (and I think common) Ruby error that 
is hidden by the NullObject pattern.

Ryan