Sha256: 55fd405aaeed70509a6aca7462becef9d06d2f08efb80b45b94032cc90216375

Contents?: true

Size: 695 Bytes

Versions: 2

Compression:

Stored size: 695 Bytes

Contents

class Proc
  def self.recursive(&block)
    Proc.new do |args|
      step = RecursiveStep.new
      returned = block.call(step, *args)

      while returned.kind_of?(RecursiveStep)
        returned = block.call(step, *returned.args)
      end

      returned
    end
  end

  def <<(func)
    Proc.new do |*args|
      func.call(self.call(*args))
    end
  end

  private

  class RecursiveStep
    attr_reader :args

    def call(*args)
      @args = args
      self
    end
  end
end

module RecursiveExtension
  def self.extended(mod)
    mod.module_eval do
      def recursive(&block)
        Proc.recursive(&block)
      end
    end
  end
end

module Kernel
  extend RecursiveExtension
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
matilda-function-0.2.0 lib/matilda-function.rb
matilda-function-0.1.0 lib/function.rb