From: hal9000@... Date: 2000-09-26T08:40:01+09:00 Subject: [ruby-talk:5114] Types and === I imagine Yoda behind me, shaking his little green head and saying, "You will never be a Jedi..." I know that the case statement uses the relationship operator ===; and I know it's different for different objects; and I know it's not commutative; and I know it's not ==. But still, one thing is a little counter-intuitive to me. 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. Comments, anyone? HF def classify1(arg) case arg.type 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 def classify2(arg) if arg.type == String print " arg is a string\n" elsif arg.type == Array print " arg is an array\n" elsif arg.type == Hash print " arg is a hash\n" else print " arg is unknown\n" end end def classify3(arg) case arg.type.to_s when String.to_s print " arg is a string\n" when Array.to_s print " arg is an array\n" when Hash.to_s print " arg is a hash\n" else print " arg is unknown\n" end end hash = {"abc"=>"def", "ghi"=>"jkl", "mno"=>"pqr"} str = "foo" arr = [1,2,3] print "\nclassify1:\n" classify1(arr) classify1(str) classify1(hash) print "\nclassify2:\n" classify2(arr) classify2(str) classify2(hash) print "\nclassify3:\n" classify3(arr) classify3(str) classify3(hash) # End of code And the output: classify1: arg is unknown arg is unknown arg is unknown classify2: arg is an array arg is a string arg is a hash classify3: arg is an array arg is a string arg is a hash -- Hal Fulton Sent via Deja.com http://www.deja.com/ Before you buy.