You might want to add a little more detail and context to your question, but if I understand correctly, you can do this without a case statement:
def create_case_range(nr, range)
range = (range | [Float::INFINITY]).sort
range.index(range.detect { |max| nr <= max }) + 1
end
Then this gives the result:
> create_case_range(68, [64,69,79,89])
=> 2
source
share