From: mame@... Date: 2019-04-29T00:05:19+00:00 Subject: [ruby-core:92470] [Ruby trunk Bug#15745] There is no symmetry in the beginless range and the endless range using `Range#inspect` Issue #15745 has been updated by mame (Yusuke Endoh). Eregon (Benoit Daloze) wrote: > I'm not sure what you mean by DSL-like usage, but I wouldn't be surprised if many people use it like `array[..-2]` (instead of `array[0..-2]`). > In other words, I'd expect it's approximately as common as endless ranges for the purpose of indexing a sequence. I meant "DSL-like", for example, `debtors = Accounts.where(balance: ...0)`. I strongly prefer `ary[0..]` to `ary[0..-1]` because the former has no magical -1. However, IMHO, there is no strong reason to prefer `ary[..-2]` to `ary[0..-2]` because 0 is not so magical in terms of indexing. It would be useful where non-zero-based indexing is used, but I don't think that it is common in Ruby. In addition, an endless range has another big usage: `(1..).each { ... }`. On the other hand, a beginless range cannot iterate. So, I believe that a beginless range has much less usages, and this is one of the reasons why a beginless range was not introduced with an endless one. That being said, I'm unsure if `Range#inspect` is mainly used for endless range. ---------------------------------------- Bug #15745: There is no symmetry in the beginless range and the endless range using `Range#inspect` https://bugs.ruby-lang.org/issues/15745#change-77818 * Author: koic (Koichi ITO) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.7.0dev (2019-04-03 trunk 67423) [x86_64-darwin17] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- The following commit introduces beginless range. https://github.com/ruby/ruby/commit/95f7992b89efd35de6b28ac095c4d3477019c583 ``` % ruby -v ruby 2.7.0dev (2019-04-03 trunk 67423) [x86_64-darwin17] ``` There is no symmetry with endless range when using `Range#inspect` method. ``` (1..).inspect # => "1.." (..5).inspect # => "nil..5" ``` How about unifying whether it represents `nil`? -- https://bugs.ruby-lang.org/ Unsubscribe: