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 <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
> => "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 `<main>'
>
> 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
>
>
>