[ruby-core:113693] [Ruby master Feature#19698] Need an idiomatic way to define an empty range

Issue #19698 has been reported by shouichi (Shouichi KAMIYA). ---------------------------------------- Feature #19698: Need an idiomatic way to define an empty range https://bugs.ruby-lang.org/issues/19698 * Author: shouichi (Shouichi KAMIYA) * Status: Open * Priority: Normal ---------------------------------------- It seems there is no idiomatic way to define an empty range. We can define empty ranges in several ways such as ``` ruby irb(main):001:0> (0...0).none? => true irb(main):002:0> (1...-1).none? => true ``` I think the above examples do not communicate the intention well. -- https://bugs.ruby-lang.org/

Issue #19698 has been updated by nobu (Nobuyoshi Nakada). What is your “intention” to use an “empty” range? And what do you think “idiomatic” way is? ---------------------------------------- Feature #19698: Need an idiomatic way to define an empty range https://bugs.ruby-lang.org/issues/19698#change-103363 * Author: shouichi (Shouichi KAMIYA) * Status: Open * Priority: Normal ---------------------------------------- It seems there is no idiomatic way to define an empty range. We can define empty ranges in several ways such as ``` ruby irb(main):001:0> (0...0).none? => true irb(main):002:0> (1...-1).none? => true ``` I think the above examples do not communicate the intention well. -- https://bugs.ruby-lang.org/

Issue #19698 has been updated by shouichi (Shouichi KAMIYA).
What is your “intention” to use an “empty” range?
In a system I'm working on, I need to represent an empty date range. We can choose two arbitrary dates d1 and d2 where d1 > d2, then use d2 as a beginning and d1 as an end of a range. For example, ``` EMPTY_RANGE = Date.new(2000, 1, 1)..Date.new(1900, 1, 1) ``` But I don't think this communicates well because d1 and d2 are too arbitrary and those concrete dates only create noises when reading code.
And what do you think “idiomatic” way is?
One idea is to add a constant e.g., `Range::EMPTY` just like `Float::EPSILON`. ---------------------------------------- Feature #19698: Need an idiomatic way to define an empty range https://bugs.ruby-lang.org/issues/19698#change-103821 * Author: shouichi (Shouichi KAMIYA) * Status: Open * Priority: Normal ---------------------------------------- It seems there is no idiomatic way to define an empty range. We can define empty ranges in several ways such as ``` ruby irb(main):001:0> (0...0).none? => true irb(main):002:0> (1...-1).none? => true ``` I think the above examples do not communicate the intention well. -- https://bugs.ruby-lang.org/
participants (3)
-
nobu (Nobuyoshi Nakada)
-
shouichi (Shouichi KAMIYA)
-
shouichi (Shouichi KAMIYA)