Issue #14699 has been updated by matz (Yukihiro Matsumoto).


I agree with @marcandre here. Let's raise exceptions.

Matz.


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

* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 2.6
* 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>