0
s = Proc.new {|x|x*2}
puts s.call(5)
-> 10
def foo(&a)
a.call(5)
end
puts "test foo:"
foo(s)
當我嘗試撥打以上PROC,我得到:引發ArgumentError調用一個Proc
foo: wrong number of arguments (1 for 0) (ArgumentError)
我的期望是,我可以通過一個進程的方法,如果該方法與此類型的定義簽名:
def foo(&a)
,然後我可以執行PROC insiide FOO這樣的:
a.call(5)
隨着「高清富(一)「你也可以」給(5)「塊。 – 2009-09-16 20:12:04