在做本页底部的练习时,
我得到了您在下面看到的解决方案的帮助:
让我继续烦恼的是第 4 行。似乎它甚至在开始写入屏幕block.call
之前就已全部运行。puts
这只是对 Ruby 的接受吗?如果我要尝试查找它,我什至将这种行为称为什么?
def log(desc, &block)
puts "Beginning #{desc}..."
#block.call seems to be occurring here!
puts "... #{desc} finished, returning: #{block.call}"
end
someLittle = lambda {5}
yetAnother = lambda {'I like Thai food!'}
outer = lambda do
log "some little block", &someLittle
log "yet another block", &yetAnother
false
end
log "outer block", &outer