Khurram wrote:
> 
> Hi all,
> 
> I was trying to develop a definition for the  === operator on a custom
> class I made.  It seems like that when I use case statements on an
> object of the class the === operator does not get invoked.  What could
> I be doing wrong?
> Here's how I'm using it.
> 
> a = MyClass.new()
> 
> case a
> when 'hello';printf "Blah....\n"
> when 'bye' ; printf "Blah....Blah...\n"
> else; printf "Blah... Blah... Blah...\n"
> end
> 
> I know I have the === operator correctly defined.. Because when I
> explicitly use it as follows then it works:
> 
>      if a === 'hello'
>         printf "Blah....\n"
>      elsif a === 'bye'
>         printf "Blah....Blah...\n"
>      else
>         printf "Blah... Blah... Blah...\n"
>      end
> 
> Any clues on what I'm doing wrong?

The case operator flips the order here.
"case a; when b ;...; end" equals "if b===a then ... end"

class A
  def ===(o)
    puts "#{self.type.to_s} === #{o.type}"
  end
end

a = A.new
s = "Hello"
case s
when a #=> A === String
end

-- 
(\[ Kent Dahl ]/)_    _~_    __[ http://www.stud.ntnu.no/~kentda/ ]___/~
 ))\_student_/((  \__d L b__/  NTNU - graduate engineering - 5. year  )
( \__\_?|?_/__/ ) _)Industrial economics and technological management(
 \____/_?_\____/ (____engineering.discipline_=_Computer::Technology___)