后续示例将无法运行

发布于 2024-09-09 02:04:44 字数 787 浏览 4 评论 0原文

我刚刚为 Ruby 安装了“sequel”gem。我想尝试 Sequel 网站上的示例,但它不起作用:( 测试.rb:

require 'rubygems'
require 'sequel'

DB = Sequel.sqlite # memory database

DB.create_table :items do
    primary_key :id
    String :name
    Float :price
end

items = DB[:items] # Create a dataset

# Populate the table
items.insert(:name => 'abc', :price => rand * 100)
items.insert(:name => 'def', :price => rand * 100)
items.insert(:name => 'ghi', :price => rand * 100)

# Print out the number of records
puts "Item count: #{items.count}"

# Print out the average price
puts "The average price is: #{items.avg(:price)}"

控制台:

$ sequel test.rb
Error: ArgumentError: syntax error on line 11, col 37: `i'/usr/lib/ruby/1.8/yaml.rb:133:in `load'

I've just installed "sequel" gem for Ruby. I wanted to try example from Sequel website and it won't work :(
test.rb:

require 'rubygems'
require 'sequel'

DB = Sequel.sqlite # memory database

DB.create_table :items do
    primary_key :id
    String :name
    Float :price
end

items = DB[:items] # Create a dataset

# Populate the table
items.insert(:name => 'abc', :price => rand * 100)
items.insert(:name => 'def', :price => rand * 100)
items.insert(:name => 'ghi', :price => rand * 100)

# Print out the number of records
puts "Item count: #{items.count}"

# Print out the average price
puts "The average price is: #{items.avg(:price)}"

Console:

$ sequel test.rb
Error: ArgumentError: syntax error on line 11, col 37: `i'/usr/lib/ruby/1.8/yaml.rb:133:in `load'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-09-16 02:04:44

您需要使用 ruby 而不是 sequel 来运行它

$ ruby test.rb

You need to run this with ruby not sequel

$ ruby test.rb
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文