When using the triple dot notation in a ruby Range object, I get this:
(0...5).each{|n| p n}
0
1
2
3
4
When I use the 'last' method I get:
(0...5).last
=> 5
I would have expected 4
Is this is a bug? Or is there something I don't understand about the the concept of a Range object?
As Stefan has answered your observed behavior is expected and documented.
If you want to obtain the last element which would be enumerated by the range without having to enumerate the whole range, you could use
Enumerable#reverse_each
This is by design. The Ruby 2.0 documentation is more specific: