[英]Ruby block - return yield running code after yield
I want to return the output of yield
but also execute the code after yield
, is there a more "right" way?: 我想返回yield
的输出,但还要在yield
之后执行代码,是否有更“正确”的方式?:
def myblock
yield_output = yield
puts 'after yield'
yield_output
end
myblock {'my yield'}
# after yield
# => my yield
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.