proc = Proc.new do |name|
puts "Thank you #{name}!"
end
def thank
yield
end
proc.call # output nothing, just fine
proc.call('God') # => Thank you God!
thank &proc # output nothing, too. Fine;
thank &proc('God') # Error!
thank &proc.call('God') # Error!
thank proc.call('God') # Error!
# So, what should I do if I have to pass the 'God' to the proc and use the 'thank' method at the same time ?
感谢您的选择 :)
thank
,而不是调用它,对吗? - Andrew Grimm,&block
不需要”,而不是“,&proc
需要”的原因。 - Marc-André Lafortunethank
方法内部,我们能否访问传递给过程的name
参数? - Masroor