Is Ruby Range comparison implemented incorrectly?

postgresql, range, ruby

Solution

These ranges aren't equal - consider the case when you call `include?` with a floating-point value:

(1 .. 2).include? 2.5
false

(1 ... 3).include? 2.5
true

They happen to return the same results if you compare them to integers, but that doesn't mean they're identical.

Problem

As in the documentation, two ranges that represent the same elements are considered different: ``` (1..2).to_a # => [1, 2] (1...3).to_a # => [1, 2] (1..2) == (1...3) # => false ``` Why are two ranges that represent the same elements are considered different? I don't think that's how it works in math though. In PostgreSQL, it is implement correctly: ``` test=# select int4range(1,2, '[]') = int4range(1,3, '[)'); ?column? ---------- t (1 row) ```

Original source