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 > rails
12388 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
class Time def set_interval(seconds) @interval = seconds end def succ @interval ||= 1 ret = self + @interval ret.set_interval(@interval) ret end end