mirror of
https://github.com/jimeh/time_ext.git
synced 2026-02-19 13:26:39 +00:00
Interation methods #each, #map_each and more are
implemented and working. Also restructured files again.
This commit is contained in:
18
lib/time_ext/method_chain.rb
Normal file
18
lib/time_ext/method_chain.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module TimeExt
|
||||
module MethodChain
|
||||
|
||||
def add_to_chain(method, *args, &block)
|
||||
@method_chain ||= []
|
||||
@method_chain << [method.to_sym, args, block]
|
||||
end
|
||||
|
||||
def call_chain(custom_block = nil, &block)
|
||||
method, args, iblock = @method_chain.pop
|
||||
return nil if method.nil?
|
||||
iblock = custom_block if !custom_block.nil?
|
||||
method, args, iblock = yield(method, args, iblock) if block_given?
|
||||
self.send(method, *args, &iblock)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user