OperatorA casereturns a value, you just need to use the correct form to get the expected value.
There are two forms in Ruby case. The first is as follows:
case expr
when expr1 then ...
when expr2 then ...
else ...
end
This will compare the expression exprwith the expression whenusing ===(this is a triple BTW) and it will execute the first thenone where ===it gives the true value. For example:
case obj
when Array then do_array_things_to(obj)
when Hash then do_hash_things_to(obj)
else raise 'nonsense!'
end
:
if(Array === obj)
do_array_things_to(obj)
elsif(Hash === obj)
do_hash_things_to(obj)
else
raise 'nonsense!'
end
case - :
case
when expr1 then ...
when expr2 then ...
else ...
end
:
case
when guess > @answer then :high
when guess < @answer then :low
else :correct
end
:
if(guess > @answer)
:high
elsif(guess < @answer)
:low
else
:correct
end
, , , ( ) :
(guess > @answer) === guess
(guess < @answer) === guess
case , .