mirror of
https://github.com/jimeh/time_ext.git
synced 2026-02-19 05:16:40 +00:00
Reordered iteration methods.
This commit is contained in:
@@ -25,6 +25,15 @@ class Time
|
|||||||
end
|
end
|
||||||
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.
|
# 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)
|
def each(unit, options = {}, &block)
|
||||||
iterate(unit, options.merge(:map_result => false), &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)
|
iterate(unit, options.merge(:map_result => true, :beginning_of => true), &block)
|
||||||
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
|
|
||||||
|
|
||||||
# Dynamically define convenience methods, like #each_hour instead of #each(:hour).
|
# Dynamically define convenience methods, like #each_hour instead of #each(:hour).
|
||||||
[:year, :month, :day, :hour, :min, :minute, :sec, :second].each do |unit|
|
[:year, :month, :day, :hour, :min, :minute, :sec, :second].each do |unit|
|
||||||
[:each, :beginning_of_each, :map_each, :map_beginning_of_each].each do |method|
|
[:each, :beginning_of_each, :map_each, :map_beginning_of_each].each do |method|
|
||||||
|
|||||||
Reference in New Issue
Block a user