The answer this doesn't work as you expect is that Class is a subclass
of Module.  If you look in the Module definitions, you will see that
for Module === is overridden to mean:

mod === anObject  -> true or false
Case Equality---Returns true if anObject is an instance of mod or one
of mod's descendents. Of limited use for modules, but can be used in
case statements to classify objects by class.

The reason for this different behavior is mentioned in the definition
above -- case statements.  It lets you do this sort of thing:

irb(main):020:0> def what_am_i(obj)
irb(main):021:1>     case obj
irb(main):022:2>     when String
irb(main):023:2>         puts "string"
irb(main):024:2>     when Hash
irb(main):025:2>         puts "hash"
irb(main):026:2>     else
irb(main):027:2*         puts "somethin else"
irb(main):028:2>     end
irb(main):029:1> end
nil
irb(main):030:0> what_am_i []
somethin else
nil
irb(main):031:0> what_am_i "ok"
string
nil

Now if you're bound and determined to do what you want to do, and I
don't know what the repurcussions of this would be, you could override
the === method in Module to use == instead of ===.  I just get the
feeling that there would be bad consequences to this.



On Wed, 2 Jun 2004 12:44:17 +0900, Luke A. Kanies <luke / madstop.com> wrote:
> 
> If I run the following code:
> 
> if Hash === Hash
>      puts "yup"
> end
> 
> I get no output.  From what I can tell, this means that I can't test
> constants in a when statement.  I need something like the following:
> 
> array.each { |member|
>    case member.class
>      when Object::Subclass
>        next
>    end
>    stuff
> }
> 
> and if I can't test the equality of constants with === (which is what
> 'when' uses; why is it a separate operator?), then I can't use them as
> values in a when statement.  How do I do this?
> 
> Thanks,
> Luke
> 
> --
> I don't always know what I'm talking about, but I'm always pretty much
> convinced that I'm right.
>                  -- musician Mojo Nixon
> ---------------------------------------------------------------------
> Luke Kanies | http://abstractive.org | http://reductiveconsulting.com
> 
>