4

我在下面的代码中遇到了这个语法错误,我不知道为什么 ruby​​ 会抱怨它。

  def user_list
  server = Lumberg::Whm::Server.new(
  host: "localhost",
  hash: IO.read("/root/.accesshash")
)

results = server.account.list
accounts = result[:params][:acct].map {|a| a["user"] }

 end
end

语法错误如下:

# bundle exec bin/userscan 
bin/userscan:3:in `require': /usr/src/userscan/lib/userscan.rb:131: syntax error, unexpected ':', expecting ')' (SyntaxError)
  host: "localhost",
       ^
/usr/src/userscan/lib/userscan.rb:131: syntax error, unexpected ',', expecting kEND
/usr/src/userscan/lib/userscan.rb:133: syntax error, unexpected ')', expecting kEND
    from bin/userscan:3

据我所知,它抱怨的部分——应该——没问题。显然,分号实际上应该在那里,括号应该包含两行的全部内容。我已经玩过它了一点,但我只是让它变得更糟而不是更好。

对我在这里搞砸的任何帮助将不胜感激。

4

1 回答 1

5

该语法host: ".."是 ruby​​ 1.9 的新语法。如果您使用的是 ruby​​ 1.8,则必须使用旧语法:

server = Lumberg::Whm::Server.new(
    :host => "localhost",
    :hash => IO.read("/root/.accesshash") )
于 2013-11-04T20:47:12.750 回答