很难说出这里要问什么。这个问题模棱两可,含糊不清,不完整,过于宽泛,或者是修辞性的,不能以现在的形式得到合理的回答。有关澄清此问题以便重新打开的帮助,请访问帮助中心。
7年前关门了。
我正在完成testfirst教学中的pig拉丁语练习,但是在生成ruby文件并尝试运行rake之后,出现以下错误:
austin-winslows-macbook-4:04_pig_latin HypnoBoy$ rake
(in /Users/HypnoBoy/Desktop/Code/learn_ruby)
/Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `gem_original_require':
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: Invalid char `\342' in expression (SyntaxError)
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: Invalid char `\200' in expression
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: Invalid char `\246' in expression
/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin.rb:15: syntax error, unexpected tIDENTIFIER, expecting ']'
word[i..-1] + cons.join()[0…i] + "ay"
^
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin_spec.rb:20
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `autorun'
from /usr/bin/rspec:23
rake aborted!
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S rspec /Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/pig_latin_spec.rb -I/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin -I/Users/HypnoBoy/Desktop/Code/learn_ruby/04_pig_latin/solution -f documentation -r ./rspec_config failed
(See full trace by running task with --trace)
我想这可能与我正在运行的版本有关,但我一点也不确定。
mac osx 10.8.2版
Ruby1.8.7
rspec第2.13.1条
耙10.0.4
注意!当我在前面的练习(0-3)上运行rake时,它们工作得很好,但之后就什么都不工作了。。。
编辑:我更新了我的rake版本,现在当我尝试运行rake时,仍然得到一个“rspec\u config failed”错误,但是我也得到了这个错误。救命!!!
/Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:156:in `run_task'
/Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:124:in `initialize'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:58:in `verbose'
/Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:122:in `send'
/Library/Ruby/Gems/1.8/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:122:in `initialize'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:246:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:184:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:205:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:183:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:101:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:101:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:73:in `run'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => default => spec
(See full trace by running task with --trace)
编辑#2:这是我的Pig拉丁语练习的源代码,因为它说这是一个语法问题。
def isvowel?(letter)
vowels = ["a", "e", "i", "o", "u"]
vowels.include?(letter)
end
def translate(word)
i = 0
cons = []
while !isvowel?(word[i])
cons << word[i]
i+=1
end
word[i..-1] + cons.join()[0…i] + "ay"
end
def translates(string)
if !string.include?(" ")
translate(string)
else
new = string.split(" ").collect { |word| translate(word) }
end
new.join(" ")
end
1条答案
按热度按时间k3bvogb11#
它被cons.join()[0…i]+“ay”噎住了-我注意到你长得很奇怪。。。这不是一个标准。。。
你复制粘贴了这部分代码吗?(一个奇怪而不受欢迎的角色)和(正确的ruby操作符)就是破坏它的原因。简单地删除另一个字符,然后用手把点写进去。