Project

General

Profile

Actions

Bug #20980

open

Range#size new TypeError vs semi-open ranges

Added by zverok (Victor Shepelev) 11 days ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-12-24T14:40:12Z master 07e89bde46) +PRISM [x86_64-linux]
[ruby-core:120397]

Description

Since #18984, Range#size throws TypeError if the begin is not iterable (doesn't respond to #succ). It produces one small inconvenience compared to 3.3:

('a'..).size #=> nil
(..'a').size 
# 3.3: nil
# 3.4: can't iterate from NilClass (TypeError) -- well, probably makes sense

# BUT:
(3..).size #=> Infinity -- cool!
(..3).size 
# 3.3: Infinity -- reasonable?
# 3.4: can't iterate from NilClass (TypeError) -- worse?

I believe that while 3.4's behavior is explainable, 3.3's one has better DX.

(Obviously too late to change before the release, but maybe might be considered for some patch version or Ruby 3.5?..)

No data to display

Actions

Also available in: Atom PDF

Like0