Reputation: 878
As far as I can tell (0..)
and (0...)
do and are the same thing, however if you look at the range documentation it says that
(1..)
and(1...)
are not equal, although technically representing the same sequence.
So I kept looking everywhere and I couldn't find what the difference is.
What differentiates the two ranges above?
Upvotes: 1
Views: 65
Reputation: 4126
From RubyDocs:
rng == obj → true or false
Returns true only if obj is a
Range
, has equivalent begin and end items (by comparing them with ==), and has the sameexclude_end?
setting as the range.
So:
(1..).exclude_end?
=> false
(1...).exclude_end?
=> true
(1..) == (1...)
=> false
So, a practically meaningless distinction, as @max says, but technically Ruby considers them to be different since one is technically infinity - 1
.
Upvotes: 4