Ruby Ranges, why is decimal included in the exclusive range?

case something
  when 0...10
    puts 'success'
  else
    puts 'fail'
end

If I enter 9.5, the result will be "successful." As far as I understand ... means that 10 will not be included, so it counts from 0 to 9? What's going on here? Also, a book with this example (I changed it so as not to copy the code), recommended for using exceptional ranges in case statements, is this considered best practice?

+4
source share
1 answer

0...10means 10not out of range. But it also means that everything is less 10(but more than 0).

Using ...instead ..does not change the end of the range:

(0..10).end
# => 10
(0...10).end
# => 10

It changes the end inclusion in this range:

(0..10).exclude_end?
# => false
(0...10).exclude_end?
# => true

Ruby : http://ruby-doc.org/core-2.0.0/Range.html

+3

All Articles