class Foo
def with_yield
yield(self)
end
def with_instance_eval(&block)
instance_eval(&block)
end
end
f = Foo.new
f.with_yield do |arg|
p self
# => main
p arg
# => #<Foo:0x100124b10>
end
f.with_instance_eval do |arg|
p self
# => #<Foo:0x100124b10>
p arg
# => #<Foo:0x100124b10>
end
p arg
2番目の' 'がFooインスタンスを報告するのはなぜですか?ブロックに譲らないnil
ので報告すべきではありませんか?with_instance_eval
self