我想访问调用者的绑定。这里有什么问题?
require 'test/unit'
class BlocksTest < Test::Unit::TestCase
class Blocks
def initialize( &block ); @block = block; end
def run; instance_eval { @block.call }; end
def foo; 'foo'; end
end
def test_say_foo_via_string
assert_equal( 'foo', Blocks.new{ 'foo' }.run )
end
# => successful
def test_say_foo_via_caller_method
assert_equal( 'foo', Blocks.new{ foo }.run )
end
# => NameError: undefined local variable or method `foo'
end
为什么我无权访问给定块内的调用者实例?