我正试图通过Koans学习Ruby,但我坚持第6步.
这是代码:
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
# What happens when you call a method that doesn't exist.
# The following begin/rescue/end code block captures the exception and
# make some assertions about it.
begin
nil.some_method_nil_doesnt_know_about
rescue Exception => ex
# What exception has been caught?
assert_equal __, ex.class
# What message was attached to the exception?
# (HINT: replace __ with part of the error message.)
assert_match(/__/, ex.message)
end
end
Run Code Online (Sandbox Code Playgroud)
我知道我应该用错误消息"NoMethodError"替换__,但我似乎无法弄明白.
这是我运行"path_to_enlightenment.rb"时收到的错误消息:
The answers you seek...
<"FILL ME IN"> expected but was <NoMethodError>.
Run Code Online (Sandbox Code Playgroud)
我真的很感激这方面的一些指导 - 它让我疯了!我很想知道答案和可能的解释.谢谢!
Ell*_*iot 12
这里的答案是"NoMethodError"
你需要在两边的项目,相同,因此使它们ex.class将这样做.
然后你需要继续/ __ /下面.