我想打電話給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