Class: Proc

Inherits:
Object show all
Defined in:
src/class.c,
mrbgems/mruby-proc-ext/mrblib/proc.rb

Overview

15.2.17

Instance Method Summary collapse

Instance Method Details

#===(*args) ⇒ Object


3
4
5
# File 'mrbgems/mruby-proc-ext/mrblib/proc.rb', line 3

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

#curry(arity = self.arity) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'mrbgems/mruby-proc-ext/mrblib/proc.rb', line 15

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

#to_procObject


11
12
13
# File 'mrbgems/mruby-proc-ext/mrblib/proc.rb', line 11

def to_proc
  self
end

#yield(*args) ⇒ Object


7
8
9
# File 'mrbgems/mruby-proc-ext/mrblib/proc.rb', line 7

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