Sha256: 945444ab6a93a920d66639d1bd3f5d3d309195dd48a4afdee738524b91c33db0

Contents?: true

Size: 973 Bytes

Versions: 12

Compression:

Stored size: 973 Bytes

Contents

class Proc

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

  def yield(*args)
    call(*args)
  end

  def to_proc
    self
  end

  def curry(arity=self.arity)
    type = :proc
    abs = lambda {|a| a < 0 ? -a - 1 : a}
    arity = abs[arity]
    if lambda?
      type = :lambda
      self_arity = self.arity
      if (self_arity >= 0 && arity != self_arity) ||
         (self_arity < 0 && abs[self_arity] > arity)
        raise ArgumentError, "wrong number of arguments (#{arity} for #{abs[self_arity]})"
      end
    end

    pproc = self
    make_curry = proc do |given_args=[]|
      __send__(type) do |*args|
        new_args = given_args + args
        if new_args.size >= arity
          pproc[*new_args]
        else
          make_curry[new_args]
        end
      end
    end
    make_curry.call
  end

  def <<(other)
    ->(*args, &block) { call(other.call(*args, &block)) }
  end

  def >>(other)
    ->(*args, &block) { other.call(call(*args, &block)) }
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
script_core-0.3.2 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.3.0 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.7 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.6 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.5 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.4 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.3 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.2 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.1 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.2.0 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.1.1 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
script_core-0.1.0 ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb