From: hal9000 / hypermetrics.com
Subject: [ruby-talk:5114] Types and ===
Date: Tue, 26 Sep 2000 08:40:01 +0900
> Reason with me: Normally when x == y, x === y is also true (I'm
> not saying the converse!!). But I have found a case where it isn't.
> I can see there may be others.)
>
> See the fragment below, and its output.
>
> classify1 and classify2 don't do the same thing. The first fails;
> the second works. classify3 also works.
ahm... I might be missing something. You said '*Normally* when x ==
y, ...', and also you said you know '==' is not '===' but assuming
Module#=== is equal to Module#== ?
try this:
o = Object.new
p (Object === o)
p (Object == o)
"Object === o" is equal to "o.is_a? Object". that makes easier to
write case statement.
def classify4(arg)
case arg
when String
print " arg is a string\n"
when Array
print " arg is an array\n"
when Hash
print " arg is a hash\n"
else
print " arg is unknown\n"
end
end
--
yashi