Ruby ranges and upper limits
If you want get maximum value of Range in Ruby, don't use Range#last.
Method Range#last returns upper limit point for any ranges:
(1..5).last #=> 5
(1...5).last #=> 5
If you use 1.8.7 or later, you need use next snippet:
range.exclude_end? ? range.last - 1 : range.last
If you use 1.9.x and higher, simple use Range#max method.
Written by Alexey Plutalov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#