Project

General

Profile

Actions

Feature #20483

open

More intuitive initialisation of null Range

Added by bodacious (Gavin Morrice) 7 months ago. Updated 7 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:117834]

Description

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:

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

Also available in: Atom PDF

Like0
Like0