jpwynn jpwynn - 4 months ago 15
Ruby Question

how to use ruby " case ... when " with inequalities?

can you do this in ruby?
it seems to "miss" the cases with inequalities

case myvar
when myvar < -5
do somethingA
when -5..-3
do special_something_XX
when -2..-1
do special_something_YY
when myvar == 0
do somethingB
when myvar > 0
go somethingC
end

Answer

You are mixing two different types of case statements:

case var
when 1
  dosomething
when 2..3
  doSomethingElse
end

case
when var == 1
   doSomething
when var < 12
   doSomethingElse
end