-3

这是我的代码(全部):

require "rubygems"
require "ruby-box"

安装了 ruby​​gems,并将 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
4

1 回答 1

3

看起来您正在使用 Ruby 1.8,但正在尝试使用 Ruby 1.9 中添加的哈希文字语法:

{ foo: bar }

在 Ruby 1.8 中,您需要编写:

{ :foo => bar }

但如果您刚刚开始,我建议您只需升级您的 Ruby 版本,而不是重写您的代码。

请注意,如果散列是方法调用的参数,则有时会省略花括号。

于 2013-08-03T12:20:19.153 回答