From: Marc-Andre Lafortune Date: 2013-03-28T23:24:28+09:00 Subject: [ruby-core:53805] Re: Meaningless nil range --047d7b339d5b083b3f04d8fcd1a7 Content-Type: text/plain; charset=ISO-8859-1 In 1.9+, you can indeed create ranges that are not very meaningful with any objects. The method `cover?` works, though. o = Object.new r = o..o r.cover?(o) # => true I don't see a good way to forbid `nil..nil` and remain generic, though. You should open a feature request if you feel strongly about this. On Thu, Mar 28, 2013 at 6:44 AM, Pascal Hurni wrote: > Hi, > > I came accross a bizarre behaviour when porting my code from 1.8.7 to > 2.0.0. > > Here are irb sessions: > > >> RUBY_VERSION > => "1.8.7" > >> nil..nil > ArgumentError: bad value for range > from (irb):2 > > 2.0.0p0 :002 > range = nil..nil > => nil..nil > 2.0.0p0 :003 > range.include? nil > TypeError: can't iterate from NilClass > from (irb):3:in `each' > from (irb):3:in `include?' > from (irb):3:in `include?' > from (irb):3 > from /Users/phi/.rvm/rubies/ruby-2.**0.0-p0/bin/irb:16:in `
' > > So a range of nil..nil throws an error in 1.8.7 but does not in 2.0.0. > While it is accepted in 2.0.0, nothing meaningful may be done with it. > I'd highly prefer the 1.8.7 behaviour of throwing an error when > constructing such a range. > > What are your opinions? > > Regards, > > Pascal > > > --047d7b339d5b083b3f04d8fcd1a7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
In 1.9+, you can indeed create ranges that are not very me= aningful with any objects. The method `cover?` works, though.

=A0 =A0 o =3D Object.new
=A0 =A0 r =3D o..o
=A0 = =A0 r.cover?(o) # =3D> true

I don't see a good way to forbid `nil..nil` and rem= ain generic, though.

You should open a feature= request if you feel strongly about this.


On Thu, Mar 28, 2013 at 6:44 AM, Pascal = Hurni <hurnip@gmail.com> wrote:
Hi,

I came accross a bizarre behaviour when porting my code from 1.8.7 to 2.0.0= .

Here are irb sessions:

>> RUBY_VERSION
=3D> "1.8.7"
>> nil..nil
ArgumentError: bad value for range
=A0 =A0 from (irb):2

2.0.0p0 :002 > range =3D nil..nil
=A0=3D> nil..nil
2.0.0p0 :003 > range.include? nil
TypeError: can't iterate from NilClass
=A0 =A0 from (irb):3:in `each'
=A0 =A0 from (irb):3:in `include?'
=A0 =A0 from (irb):3:in `include?'
=A0 =A0 from (irb):3
=A0 =A0 from /Users/phi/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<= ;main>'

So a range of nil..nil throws an error in 1.8.7 but does not in 2.0.0. Whil= e it is accepted in 2.0.0, nothing meaningful may be done with it.
I'd highly prefer the 1.8.7 behaviour of throwing an error when constru= cting such a range.

What are your opinions?

Regards,

Pascal



--047d7b339d5b083b3f04d8fcd1a7--