在以下 ruby 代码中实现 Yield



我使用并处理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只是执行两次。

最新更新