2012-08-23 25 views
0

我正在RubyKoans.com上工作,並被卡住在about_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 
    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' --------------- 

回答

3

這就是答案。假設將錯誤放在括號中。

def test_symbols_cannot_be_concatenated 
    # Exceptions will be pondered further father down the path 
    assert_raise(NoMethodError) do 
     :cats + :dogs 
    end 
    end 
4

當你被困在一個公案中時,只需在irb中試試。它可以幫助你知道要填寫什麼。

$ irb 
>> :symbol + :another_symbol 
NoMethodError: undefined method `+' for :symbol:Symbol 
from (irb):2