On Monday 02 June 2008 17:48:38 Joel VanderWerf wrote:
> David Masover wrote:
> > Give me an example of a class that isn't a category.
> > 
> > It might not be a category as far as your program logic is concerned, but 
it's 
> > certainly a category of some kind. NilClass is a category of objects for 
whom 
> > #nil? returns true, for example.
> 
> class MyNil
>    def nil?
>      true
>    end
> end
> 
> p MyNil.new.nil?

Interesting that this works -- but it doesn't disprove my point. Humans are a 
category of mammals -- that doesn't imply that all mammals are humans.

Now, technically, you should be able to do it the other way around, right?

class NilClass
  def nil?
    false
  end
end

That would make my statement invalid. But doing so is evil:

$ irb
irb(main):001:0> # Control statement
irb(main):002:0* true
=> true
irb(main):003:0> class NilClass
irb(main):004:1> def nil?
irb(main):005:2> false
irb(main):006:2> end
irb(main):007:1> end
=>
irb(main):008:0> # Another control statement... can we make it that far?
/usr/lib/ruby/1.8/irb/slex.rb:235:in `match_io': undefined method `call' for 
nil:NilClass (NoMethodError)
        from /usr/lib/ruby/1.8/irb/slex.rb:222:in `match_io'
        from /usr/lib/ruby/1.8/irb/slex.rb:76:in `match'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:287:in `token'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:263:in `lex'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:234:in 
`each_top_level_statement'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in 
`each_top_level_statement'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
        from /usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in 
`each_top_level_statement'
        from /usr/lib/ruby/1.8/irb.rb:146:in `eval_input'
        from /usr/lib/ruby/1.8/irb.rb:70:in `start'
        from /usr/lib/ruby/1.8/irb.rb:69:in `catch'
        from /usr/lib/ruby/1.8/irb.rb:69:in `start'
        from /usr/bin/irb:13