Sha256: 5a12e6327fd48aaddc97868c5eb031cf40670350dd4dec6fda380f3edb443e2f

Contents?: true

Size: 763 Bytes

Versions: 11

Compression:

Stored size: 763 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)
    abs = lambda {|a| a < 0 ? -a - 1 : a}
    arity = abs[arity]
    if 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=[]|
      proc 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

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
webruby-0.9.3 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.9.2 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.9.1 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.2.7 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.2.5 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.2.4 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.2.2 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.2.1 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.1.2 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.1.1 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb
webruby-0.1.0 modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb