Ruby: make ranges always include the last value
class Range def each(options = {}, &block) val = self.begin while val < self.end yield val val = val.succ end yield self.end if self.end == val || options[:always_include_last] end end
DZone Snippets > technodolt > range
12364 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Luke Ivers http://technodolt.blogspot.com
class Range def each(options = {}, &block) val = self.begin while val < self.end yield val val = val.succ end yield self.end if self.end == val || options[:always_include_last] end end