我在教自己鲁比。我不认识谁知道它,所以我没有人可以帮助我非常简单,也许是烦人的问题。我正在运行以下代码并获得以下错误:
def simon_says (command)
def echo (param)
puts "#{param}"
end
end错误:
PS R:\learn_ruby\03_simon_says> rake
(in R:/learn_ruby)
You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows
Simon says
echo
should echo hello (FAILED - 1)
Failures:
1) Simon says echo should echo hello
Failure/Error: echo("hello").should == "hello"
NoMethodError:
undefined method `echo' for #RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x2fb5690>
# ./03_simon_says/simon_says_spec.rb:19:in `block (3 levels) in <top (required)>'
Finished in 0.003 seconds
1 example, 1 failureRspec代码可以在这里找到(Github):spec.rb
我真的不知道怎么回事。为什么要说“回声”是未知的?在我看来是明确的。我还尝试输出"hello“本身,而不是方法参数(param)。同样的错误。所有的帮助都很感激。而且,如果有人知道一个更合适的地方,我可以得到这样的帮助,这将是很好的。
发布于 2014-04-01 02:26:08
根据你的规范,我想simon_says是一流的。这不是方法。您正在定义方法内部的方法。尝尝这个
class SimonSays
def echo params
puts "#{params}"
end
endhttps://stackoverflow.com/questions/22775540
复制相似问题