Ruby uses `===` operator on the `case/when` type execution style.Now It
also known that Ruby depending on the type
of the thing present in the `when` clause, calls the respective `.===`
method.

Say `when` statement contains the `class` names, then the rule is - ` it
will use Module#===, which will return true if the right side is an
instance of,
or subclass of, the left side.` One example with this context is:

Here `instance of` test occurs

obj = 'hello'
#=> "hello"
case obj
when String
print 'It is a string'
when Fixnum
print 'It is a number'
else
print 'It is not a string'
end
#It is a string
#=> nil

Here `subclass of` test occurs

num = 10
#=> 10
case num
when Numeric
puts "Right class"
else
puts "Wrong class"
end
#Right class
#=> nil

Now `when` contains `String` literals then String#=== is called, which
in turn checks if left and right handside
literal are same(same chracter in same sequence) or not.

a = "abc"
#=> "abc"
case a
when "def" then p "Hi"
when "abc" then p "found"
else "not found"
end
#"found"
#=> "found"

The all logic is too cool. Now my query is with `case/when` structure -

How does ruby know if `when` holding `class`, or `String` literals or
anything valid at runtime?

or

What test does it perform before calling the respective `.===` operator.

-- 
Posted via http://www.ruby-forum.com/.