This is a classic Ruby bug. case has two call methods: one in which you pass the thing to which the branch is being kept, and one where you do not.
If you specify an expression in a case expression, then all other conditions are evaluated and compared with === . In this case, org <= 1 evaluates to false and org === false is obviously incorrect. The same applies to all other cases, they are either true or false. This means that none of them matches.
If you do not specify an expression, then case behaves like a fancy if .
Switch case org to case and it works. You can also switch to ranges:
val = case org when 0..1 'L' when 2..3 'M' else 'H' end
The way your source code runs is like this:
org = 4 if (org <= 1) === org val = 'L' elsif (2..3) === org val = 'M' elsif (org >= 4) === org val = 'H' end
This is not what you want.
source share