Project

General

Profile

Actions

Bug #20487

closed

1..nil is giving range from 1 to inifinity in ruby greater than 2.6

Added by akshay_kakade (Akshay Kakade) about 2 months ago. Updated about 2 months ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:117862]

Description

we consider nil as undefined value, value that is not present, we consider nil as falsey value as well, when we do nil.to_i it gives us zero..then with this rational 1..nil shouldn't give the range 1 to infinity, either we should make it as invalid or it should be converted to 1..0

script:

(1..nil).each {|n| puts n }

output
1
2
3
4
5
6
7
.
.
.
.
infinity


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12912: An endless range `(1..)`ClosedActions

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

  • Status changed from Open to Rejected

This is expected behavior. nil is the implicit end of an endless range:

(1..) == (1..nil)
# => true

(1..nil)
# => 1..

(1..).end
# => nil
Actions #2

Updated by mame (Yusuke Endoh) about 2 months ago

Actions

Also available in: Atom PDF

Like0
Like0Like0