2012/3/18 Intransition [email protected]:
That is incorrect. Range is really more a sequence than it is an interval.
Range is both a sequence and an interval, and this is deeply wrong.
Consider:
irb(main):008:0> r = ‘a’…‘aa’
=> “a”…“aa”
irb(main):009:0> r.to_a
=> [“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”,
“n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, "
x", “y”, “z”, “aa”]
irb(main):010:0> r.include? ‘c’
=> true
irb(main):011:0> r.cover? ‘c’
=> false
It’s false. I don’t know about you, but this seems quite
counter-intuitive. #to_a and #include? treat range as a sequence,
#cover? as an interval. But it’s just the beginning:
irb(main):012:0> r = ‘b’…‘aa’
=> “b”…“aa”
irb(main):013:0> r.to_a
=> []
irb(main):014:0> r.cover? ‘c’
=> false
irb(main):015:0> r.include? ‘c’
=> false
Explain these three to me, would you. I think this was some time ago
reported to Ruby’s bug tracker, the conclusion was that Range has a
“feature” that if start compares as bigger than end, it won’t bother
generating the sequence - this obviously fails for many non-numeric
ranges, as the one above. I don’t think anything was done about it,
though.
– Matma R.