instance_exec allows you pass arguments to the block which is to be evaluated in the new self:
o = Struct.new(:val).new("Hello")
o.instance_exec("World!"){|arg| val + " " + arg} # => Hello World!
reference: http://eigenclass.org/hiki.rb?instance_exec
本文介绍 Ruby 中的 instance_exec 方法,该方法允许将参数传递给要以新的 self 进行评估的块。通过示例展示了如何使用此方法实现字符串拼接。
1997

被折叠的 条评论
为什么被折叠?



