我正在尝试执行以下操作:
class Tester
def some_test
Proc.new do
def prep_test
end
def do_test
end
def pass?
end
end
end
def another_test
Proc.new ..
...
end
end
# tests are mapped in array_of_tests
def run
array_of_tests.each do |t|
t.call.prep_test
t.call.do_test
t.call.pass?
end
end
end
Tester.new.run
但是当我开始尝试执行每个测试t
时,我会得到类似的东西:
NoMethodError: undefined method `prep_test' for nil:NilClass
在实验中,我发现这很有效:
def test3
Proc.new do
def prep
"running test3: prep"
end
def run
"running test3: run"
end
def verify
"running test3: verify"
end
end
end
t = test3
t.call.prep
t.call.run
t.call.verify
但这不在课堂上。
我缺少什么来引用内部的嵌套方法some_test
来Tester.new.run
工作?