Project

General

Profile

Actions

Bug #18983

closed

Range#size for beginless Range is not nil.

Added by masasakano (Masa Sakano) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
[ruby-core:109770]

Description

Range#size should, according to Official docs,

Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

(..?a).size      # => Infinity
(nil..nil).size  # => Infinity

whereas it certainly does with endless Ranges

(?a..).size      # => nil

Files

bug-20220829-beginless_range.rb (1.24 KB) bug-20220829-beginless_range.rb Ruby executable code to demonstrate the point re beginless Range#size. masasakano (Masa Sakano), 08/29/2022 02:05 PM
6378.patch (1.37 KB) 6378.patch thiagofm (Thiago Massa), 09/14/2022 09:58 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #14699: Subtle behaviors with endless rangeClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0