【发布时间】:2023-01-12 17:13:07
【问题描述】:
def do_whatever # func A receives func B
params = { test: 1 }
proc = Proc.new{ puts "an important exec #{params[:test]}"; return "important response" } # func C
yield(proc)
end
do_whatever do
begin # func B
resp = yield # executes func C
puts resp
rescue => e
puts e
end
end
嗨,我想要一个函数(例如 func A)传递一个函数块(例如 func B)并执行它。该函数块(例如函数 B)还接收在该函数中初始化的函数块(例如 func C)。在上面的代码中,我希望看到输出:
an important exec 1
important response
但是我得到了一个错误:没有给出块(产量)
【问题讨论】: