source: EcnlProtoTool/trunk/mruby-1.2.0/mrbgems/mruby-proc-ext/mrblib/proc.rb@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 807 bytes
Line 
1class Proc
2
3 def ===(*args)
4 call(*args)
5 end
6
7 def yield(*args)
8 call(*args)
9 end
10
11 def to_proc
12 self
13 end
14
15 def curry(arity=self.arity)
16 type = :proc
17 abs = lambda {|a| a < 0 ? -a - 1 : a}
18 arity = abs[arity]
19 if lambda?
20 type = :lambda
21 self_arity = self.arity
22 if (self_arity >= 0 && arity != self_arity) ||
23 (self_arity < 0 && abs[self_arity] > arity)
24 raise ArgumentError, "wrong number of arguments (#{arity} for #{abs[self_arity]})"
25 end
26 end
27
28 pproc = self
29 make_curry = proc do |given_args=[]|
30 send(type) do |*args|
31 new_args = given_args + args
32 if new_args.size >= arity
33 pproc[*new_args]
34 else
35 make_curry[new_args]
36 end
37 end
38 end
39 make_curry.call
40 end
41
42end
Note: See TracBrowser for help on using the repository browser.