Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 鲁比:卡在一只可兰经上了_Ruby_Exception Handling - Fatal编程技术网

Ruby 鲁比:卡在一只可兰经上了

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

我在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
  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