Iโm personally not sure if youโd better not work with if statements, but if you want to find a solution in this form:
Inf = 1.0/0 case myvar when -Inf..-5 do somethingA when -5..-3 do special_something_XX when -2..-1 do special_something_YY when 0 do somethingB when 0..Inf do somethingC end
The following is my decision. Here, the order matters, and you need to repeat myvar , but itโs much harder not to take cases into account, you donโt need to repeat each binding twice, and the rigor ( < vs <= , not .. vs ... ) is much more obvious.
if myvar <= -5 # less than -5 elsif myvar <= -3 # between -5 and -3 elsif myvar <= -1 # between -3 and -1 elsif myvar <= 0 # between -1 and 0 else # larger than 0 end
Peter Feb 25 '11 at 7:19 2011-02-25 07:19
source share