James Britt schrieb:
> You can change the workings of a singleton class (NilClass) such that it 
> behaves differently in separate, simultaneous threads?

Yes you can, with thread-local variables:

   class NilClass

     def method_missing( m )
       super unless Thread.current[ :blackhole ]
     end

     def blackhole=( status )
       Thread.current[ :blackhole ] = status
     end

   end


   5.times do |i|
     Thread.new( i ) do |id|
       nil.blackhole = ( rand < 0.5 )
       5.times do
         puts( "thread #{id}: #{nil.reverse.inspect rescue $!}" )
         sleep 0.1
       end
     end
   end
   sleep 1


Output:

   thread 0: nil
   thread 1: undefined method `reverse' for nil:NilClass
   thread 2: nil
   thread 3: undefined method `reverse' for nil:NilClass
   thread 4: nil
   thread 4: nil
   thread 2: nil
   thread 1: undefined method `reverse' for nil:NilClass
   thread 0: nil
   thread 3: undefined method `reverse' for nil:NilClass
   ...

Regards,
Pit