假设我有以下过程:
a = Proc.new do
puts "start"
yield
puts "end"
end
还假设我传递a
给另一个方法,该方法随后instance_eval
使用该块调用另一个类,我现在如何将一个块传递到该方法的末尾,该方法在a
.
例如:
def do_something(a,&b)
AnotherClass.instance_eval(&a) # how can I pass b to a here?
end
a = Proc.new do
puts "start"
yield
puts "end"
end
do_something(a) do
puts "this block is b!"
end
输出当然应该是:
start
this block is b!
end
如何将辅助块传递给instance_eval
?
我需要这样的东西作为我正在研究的 Ruby 模板系统的基础。