Sha256: f082230bc9fe7a93f111764c167bd3bce5abf8da6f994b6fb1baaa12c8a51486

Contents?: true

Size: 581 Bytes

Versions: 1

Compression:

Stored size: 581 Bytes

Contents

module TimeExt
  # Allows iterators' #until and #from methods to chain back to the parent iteration method.
  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_ext-0.2.1 lib/time_ext/method_chain.rb