这是我的代码(全部代码):
require "rubygems"
require "ruby-box"
安装了rubygems,并将ruby-box安装为gem。这是我的错误:
Faraday: you may want to install system_timer for reliable timeouts
/Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `gem_original_require': /Library/Ruby/Gems/1.8/gems/ruby-box-1.9.1/lib/ruby-box/item.rb:91: odd number list for Hash (SyntaxError)
access: 'open'
^
/Library/Ruby/Gems/1.8/gems/ruby-box-1.9.1/lib/ruby-box/item.rb:91: syntax error, unexpected ':', expecting '}'
access: 'open'
^
/Library/Ruby/Gems/1.8/gems/ruby-box-1.9.1/lib/ruby-box/item.rb:92: syntax error, unexpected '}', expecting kEND
}.merge(opts) if opts
^
/Library/Ruby/Gems/1.8/gems/ruby-box-1.9.1/lib/ruby-box/item.rb:102: odd number list for Hash
shared_link: opts
^
/Library/Ruby/Gems/1.8/gems/ruby-box-1.9.1/lib/ruby-box/item.rb:102: syntax error, unexpected ':', expecting '}'
shared_link: opts
^
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Library/Ruby/Gems/1.8/gems/ruby-box-1.9.1/lib/ruby-box.rb:4
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:110:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:110:in `require'
from box.rb:2
答案 0 :(得分:3)
看起来你正在使用Ruby 1.8但是正在尝试使用Ruby 1.9中添加的哈希文字语法:
{ foo: bar }
在Ruby 1.8中,你需要写:
{ :foo => bar }
但是,如果您刚开始使用,我建议您只需升级Ruby版本,而不是重写代码。
请注意,如果哈希是方法调用的参数,则有时会省略花括号。