I wanted to check if my_number was in a certain range, including the higher Value.
In an IF Statement I\'d simply use \"x > 100 && x <= 500\"
But
Here's a case way to capture "x > 100 && x <= 500 as desired: a value in a closed range with the start value excluded and the end value included. Also, capturing the ranges before and after that is shown.
case my_number
when ..100; puts '≤100'
when 100..500; puts '>100 and ≤500'
when 500..; puts '>500'
end
Explanations:
-Infinity resp. go to Infinity. This was introduced in Ruby 2.6.x..y include the end value, ranges x...y exclude the end value.when case. That is how the second when case is equivalent to your "x > 100 && x <= 500 even though (100..500).include? 100. Similarly for the third case.