Actions
Bug #6730
closedlast method not really returning last element of range
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin10.8.0]
Backport:
Description
1.9.2p320 :001 > (0...5).each {|n| p n}
0
1
2
3
4
=> 0...5
1.9.2p320 :002 > (0...5).last(2)
=> [3, 4]
1.9.2p320 :003 > (0...5).last
=> 5
1.9.2p320 :004 >
The last method on line number 003 should return 4
Updated by drbrain (Eric Hodel) over 12 years ago
- Category set to core
- Status changed from Open to Rejected
This is by design, please check the documentation before filing a bug:
$ ri Range#last
Range#last
(from ruby core)¶
rng.last -> obj
rng.last(n) -> an_array
Returns the last object in the range, or an array of the last n
elements.
Note that with no arguments last will return the object that defines
the end of the range even if #exclude_end? is true.
(10..20).last #=> 20
(10...20).last #=> 20
(10..20).last(3) #=> [18, 19, 20]
(10...20).last(3) #=> [17, 18, 19]
Actions
Like0
Like0