我想打电话给instance_eval这个类: class A
attr_reader :att
end
通过这个方法b: class B
def b(*args)
att
end
end
,但这种情况正在发生: a = A.new
bb = B.new
a.instance_eval(&bb.method(:b)) # NameError:
有谁知道是什么原因导致了这个错误?我正在尝试制作基本的机架应用程序。 App.rb => class Cherry
class << self
def app &block
Cherry::Application.new &block
end
end
class Application
def initialize
如果我有一个类: class KlassWithSecret
def initialize
@secret = 99
end
end
并运行: puts KlassWithSecret.new.instance_eval { @secret }
它打印99,但是如果我跑: puts KlassWithSecret.new.instance_eval do
我的红宝石DSL的用户希望能够添加额外的方法和任意块的上下文中调用它们,例如: def do_something
override 'flags', 'ABC'
end
project('XXX') do
configuration('debug') do
do_something
end
end
在这个示例'override'是一个用ins