Ruby 鲁比:卡在一只可兰经上了
我在RubyKoans.com上工作,被这个koan困在了关于_symbols.rb的网站上 这就是测试:我假设我应该在assert_raise之后在括号中放一些东西,但我不知道:Ruby 鲁比:卡在一只可兰经上了,ruby,exception-handling,Ruby,Exception Handling,我在RubyKoans.com上工作,被这个koan困在了关于_symbols.rb的网站上 这就是测试:我假设我应该在assert_raise之后在括号中放一些东西,但我不知道: def test_symbols_cannot_be_concatenated # Exceptions will be pondered further father down the path assert_raise(___) do :cats + :dogs end e
def test_symbols_cannot_be_concatenated
# Exceptions will be pondered further father down the path
assert_raise(___) do
:cats + :dogs
end
end
这是终端中的提示:
The answers you seek...
[FillMeInError] exception expected, not Class: <NoMethodError> Message: <"undefined method `+' for :cats:Symbol"> ---Backtrace--- /Users/mm/Sites/koans/about_symbols.rb:89:in `block in test_symbols_cannot_be_concatenated' ---------------
这就是答案。应该把错误放在括号里
def test_symbols_cannot_be_concatenated
# Exceptions will be pondered further father down the path
assert_raise(NoMethodError) do
:cats + :dogs
end
end
当你被卡在koan上时,就在irb上试试。它可以帮助你知道填充什么
$ irb
>> :symbol + :another_symbol
NoMethodError: undefined method `+' for :symbol:Symbol
from (irb):2