Reordered iteration methods.

This commit is contained in:
2010-07-29 14:01:12 +03:00
parent d052a720e4
commit eb6ee05a3e

View File

@@ -25,6 +25,15 @@ class Time
end
end
# Used togeter with #each to specify end of interation.
def until(time, &block)
time = time.to_time if time.is_a?(::Date)
@until = time
return call_chain(block) if block_given?
self
end
alias :till :until
# Executes passed block for each "unit" of time specified, with a new time object for each interval passed to the block.
def each(unit, options = {}, &block)
iterate(unit, options.merge(:map_result => false), &block)
@@ -45,15 +54,6 @@ class Time
iterate(unit, options.merge(:map_result => true, :beginning_of => true), &block)
end
# Used togeter with #each to specify end of interation.
def until(time, &block)
time = time.to_time if time.is_a?(::Date)
@until = time
return call_chain(block) if block_given?
self
end
alias :till :until
# Dynamically define convenience methods, like #each_hour instead of #each(:hour).
[:year, :month, :day, :hour, :min, :minute, :sec, :second].each do |unit|
[:each, :beginning_of_each, :map_each, :map_beginning_of_each].each do |method|