Actions
Bug #20487
closed1..nil is giving range from 1 to inifinity in ruby greater than 2.6
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
Updated by jeremyevans0 (Jeremy Evans) 6 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
Updated by mame (Yusuke Endoh) 6 months ago
- Related to Feature #12912: An endless range `(1..)` added
Actions
Like0
Like0Like0