Project

General

Profile

Actions

Bug #14699

closed

Subtle behaviors with endless range

Added by mame (Yusuke Endoh) almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Assignee:
-
Target version:
[ruby-core:86612]

Description

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.


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #12912: An endless range `(1..)`ClosedActions
Related to Ruby master - Bug #18983: Range#size for beginless Range is not nil.ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0