我使用并处理Java和C#。
我被要求在遵循Ruby代码时解释Yield。
法典:
mine=15
puts "Mine = 15"
def call_block
yield
yield
puts 'Now for some magic!'
end
call_block {mine}
print "Mine now is "
puts mine
输出:
mine = 15
now for some Magic!
mine now is 25
问题是如何使用上面的代码获取此输出。
我对产量了解不多,这就是为什么代码不正确的原因。
我认为必须在某个地方添加 10 个,但在哪里?
任何帮助将不胜感激。
将{mine}
更改为{mine+=5}
。 yield
只是执行两次。