所以我正在研究 Ruby Koans ,而且我遇到了一个我认为是 ruby
1.9.x 特有的问题。
def test_calling_global_methods_without_parentheses
result = my_global_method 2, 3
assert_equal 5, result
end
我明白了:
james@tristan:~/code/ruby_projects/ruby_koans$ rake
(in /home/james/code/ruby_projects/ruby_koans)
cd koans
/home/james/.rvm/rubies/ruby-1.9.2-p180/bin/ruby path_to_enlightenment.rb
/home/james/code/ruby_projects/ruby_koans/koans/about_methods.rb:21:in `eval': (eval):1: syntax error, unexpected tINTEGER, expecting keyword_do or '{' or '(' (SyntaxError)
assert_equal 5, my_global_method 2, 3
^
from /home/james/code/ruby_projects/ruby_koans/koans/about_methods.rb:21:in `test_sometimes_missing_parentheses_are_ambiguous'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:377:in `meditate'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:449:in `block in walk'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:460:in `block (3 levels) in each_step'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:458:in `each'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:458:in `block (2 levels) in each_step'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:457:in `each'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:457:in `each_with_index'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:457:in `block in each_step'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:455:in `catch'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:455:in `each_step'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:448:in `walk'
from /home/james/code/ruby_projects/ruby_koans/koans/edgecase.rb:470:in `block in <top (required)>'
rake aborted!
Command failed with status (1): [/home/james/.rvm/rubies/ruby-1.9.2-p180/bi...]
/home/james/code/ruby_projects/ruby_koans/Rakefile:86:in `block in <top (required)>'
(See full trace by running task with --trace)
james@tristan:~/code/ruby_projects/ruby_koans$
我在 GitHub 上查看了几个声称最近(过去两个月)完成了 Koans 的不同存储库,但我只看到了我使用的答案(第一个代码片段)。那么,是我的代码、我的 Ruby 安装还是其他原因?
最佳答案
您得到的错误不是来自您列出的代码;它来自它下面的代码。 See line 20的相关文件。注释说:
NOTE: We are Using eval below because the example code considered to be syntactically invalid
关于ruby - 我可以在 Ruby 1.9.x 中使用无参数函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5346564/