e$B!!$5$5$@$G$9!#e(B
e$B!!%V%m%C%/%Q%i%a!<%?$K$D$$$F!"<+J,$,GD0.$7$F$$$kJ,$K$D$$$F$O<Be(B
e$BAu$7$^$7$?!#$J$s$+H4$1$,$"$C$?$i65$($F$/$@$5$$!#e(B
e$B!!e(B1.8 e$B$H$NAj0cE@$O!"$?$V$s$3$s$J$H$3$m$G$9!'e(B
e$B!&J#?t0z?t$G$Ne(B yield e$B$r!"e(B1
e$B0z?t$N>l9gG[Ns$H$7$F$&$1$J$$e(B
–
ruby -ve “Proc.new{|a| p a}.call(1, 2)”
ruby 1.8.5 (2006-08-25) [i486-linux]
-e:1: warning: multiple values for a block parameter (2 for 1)
from -e:1
[1, 2]
./miniruby -ve “Proc.new{|a| p a}.call(1, 2)”
ruby 1.9.0 (2007-06-25 patchlevel 0) [i686-linux]
1
e$B!&e(Bpost arg e$B$NBP1~e(B
e$B!!$3$l!“0lE@Fq$7$$%]%$%s%H$,$”$C$F!“e(B|a, b, *r, p1, p2|
e$B$N$H$-e(B
e$B$K!”!Ve(B3e$B0z?t!WEO$5$l$?$H$-!“e(Bp1 e$B$b$7$/$Oe(B
p2e$B!”$I$A$i$KF~$l$k$Y$-e(B
e$B$G$7$g$&$+!#$H$j$"$($:!":G8e$Ke(B nil e$B$r$D$a$?$H2r<a$7!"e(Bp1
e$B$XBeF~e(B
e$B$9$k$h$&$K<BAu$7$^$7$?!#e(B
e$B!&%*%W%7%g%J%k0z?t$NBP1~!Je(Blambdae$B!Ke(B
e$B!&%V%m%C%/0z?t$NBP1~e(B
e$B!&<B9TNc!'e(B
p :lambda
f = -> (m1, m2, o1=:o1, o2=:o2, *r, p1, p2) {[m1, m2, o1, o2,
r, p1, p2]}
(4…10).each{|e|
p ary = (0…e).to_a
p f.call(*ary)
puts
}
p :Proc
pr = Proc.new{|m1, m2, m3, *r, p1, p2, p3| [m1, m2, m3, r, p1,
p2, p3]}
(0…10).each{|e|
p ary = (0…e).to_a
p ary = pr.call(*ary)
puts
}
#=>
:lambda
[0, 1, 2, 3]
[0, 1, :o1, :o2, [], 2, 3]
[0, 1, 2, 3, 4]
[0, 1, 2, :o2, [], 3, 4]
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, [], 4, 5]
[0, 1, 2, 3, 4, 5, 6]
[0, 1, 2, 3, [4], 5, 6]
[0, 1, 2, 3, 4, 5, 6, 7]
[0, 1, 2, 3, [4, 5], 6, 7]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[0, 1, 2, 3, [4, 5, 6], 7, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, [4, 5, 6, 7], 8, 9]
:Proc
[]
[nil, nil, nil, [], nil, nil, nil]
[0]
[0, nil, nil, [], nil, nil, nil]
[0, 1]
[0, 1, nil, [], nil, nil, nil]
[0, 1, 2]
[0, 1, 2, [], nil, nil, nil]
[0, 1, 2, 3]
[0, 1, 2, [], 3, nil, nil]
[0, 1, 2, 3, 4]
[0, 1, 2, [], 3, 4, nil]
[0, 1, 2, 3, 4, 5]
[0, 1, 2, [], 3, 4, 5]
[0, 1, 2, 3, 4, 5, 6]
[0, 1, 2, [3], 4, 5, 6]
[0, 1, 2, 3, 4, 5, 6, 7]
[0, 1, 2, [3, 4], 5, 6, 7]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[0, 1, 2, [3, 4, 5], 6, 7, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, [3, 4, 5, 6], 7, 8, 9]