From: "bodacious (Gavin Morrice) via ruby-core" <ruby-core@...>
Date: 2024-05-11T18:12:04+00:00
Subject: [ruby-core:117834] [Ruby master Feature#20483] More intuitive initialisation of null Range

Issue #20483 has been reported by bodacious (Gavin Morrice).

----------------------------------------
Feature #20483: More intuitive initialisation of null Range 
https://bugs.ruby-lang.org/issues/20483

* Author: bodacious (Gavin Morrice)
* Status: Open
----------------------------------------
Hi all ��������

I've come across cases where I want a method to return a Range. In some cases, the Range should be empty. 

I see from the documentation, that it's possible to initialise a null Range by passing in values where a is greater than b `Range.new(1, -1)`.

I find this particular notation to be unclear, and likely to be discouraged by my team because it's unclear. 

I'm opening this discussion to see if there's any interest in support for a simpler notation for null (empty) Ranges. Something like: 

``` ruby
r = Range.new(nil) # notation not currently supported
r.size # => 0
r.max # => nil
r.min # => nil
r.each { puts "This is never called" }
```




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/