Issue #14699 has been updated by marcandre (Marc-Andre Lafortune).


I believe `(0..).max(3)` and `(0..).max {|a, b| a <=> b }` can not return `nil`. They should either hang or (seems more useful) raise an error, same as `min`. I would have `(0..).last(3)` also raise an error.

`(0..).size` must return `Float::INFINITY`, not `nil`. The only reason why `("a".."z").size` returns `nil` was that I was too lazy to code a valid calculation that handled all the strange corner cases of the way we iterate on strings.

----------------------------------------
Bug #14699: Subtle behaviors with endless range
https://bugs.ruby-lang.org/issues/14699#change-71575

* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Currently, some Range's methods behaves weirdly with endless range.

## Range#max

Range#max always returns nil.  Is this okay, or is another result expected? 

```
p (0..).max #=> nil
p (0..).max(3) #=> nil
p (0..).max {|a, b| a <=> b } #=> nil
```

Note that `(0..).min {|a, b| a <=> b }` gets stuck.  I think Range#min and Range#max should behave the same if a block are passed, but I'm uncertain what behavior is preferable.

## Range#last

Range#last returns nil if no argument is passed.  But it gets stuck if a length argument is passed.  Is this okay?

```
p (0..).last #=> nil
p (0..).last(3) #=> stuck
```

## Range#size

Range#size returns nil for endless range.  I think this is somewhat reasonable because `("a".."z").size` returns nil.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>