From: Brian Candler on
Kenneth     wrote:
> Ruby switches expand to the === operator, for example:
>
> case string
> when "" then puts "Empty"
> when /^a/ then puts "Starts with a"
> end
>
> is equivalent to:
>
> if string === ""
> puts "Empty"
> elsif string === /^a/
> puts "Contains a"
> end

Actually the arguments are the other way round:

if "" === string
puts "Empty"
elsif /^a/ === string
puts "Starts with a"
end

Another example:

case arg
when String; puts "it's a string"
when Numeric; puts "it's a number"
end

The first expands to String === arg, which is functionally equivalent to
arg.is_a?(String)
--
Posted via http://www.ruby-forum.com/.

From: John Crichton on
Thank you all for your replies/answers. I appreciate the help and
explanations.
--
Posted via http://www.ruby-forum.com/.