代码@db = SQLite3::Database.new 'db.db'
与ruby-1.9.3-p194完美配合,并使用ruby-2.0.0-p353(rvm 1.24.7)返回错误:
wrong argument type nil (expected Hash) (TypeError)
我无法使用Google搜索任何解决方案。
UPD :irb没有错误。只有我自己的代码:
# encoding: utf-8
require 'sqlite3'
class Model
attr_reader :files, :last
def initialize(dbPath = 'photo.db', tags = '', lastID = 0)
@tags = tags
@lastID = lastID
$log.debug() {"Loading database: #{dbPath}..."}
@db = SQLite3::Database.new dbPath
end
...
它在日志中生成此跟踪:
I, [2013-12-29T12:03:30.586180 #8961] INFO -- : ---===== S T A R T E D =====--- I, [2013-12-29T12:03:30.587922 #8961] INFO -- : Config /home/michael/Projects/Ruby/SPS/config.yml loaded D, [2013-12-29T12:03:30.588072 #8961] DEBUG -- : Loading database: /home/michael/.local/share/shotwell/data/photo.db... F, [2013-12-29T12:03:30.588207 #8961] FATAL -- : wrong argument type nil (expected Hash) (TypeError) /home/michael/Projects/Ruby/SPS/model.rb:11:in `initialize' /home/michael/Projects/Ruby/SPS/model.rb:11:in `new' /home/michael/Projects/Ruby/SPS/model.rb:11:in `initialize' /home/michael/Projects/Ruby/SPS/controller.rb:11:in `new' /home/michael/Projects/Ruby/SPS/controller.rb:11:in `initialize' ./main.rb:10:in `new' ./main.rb:10:in `'
答案 0 :(得分:1)
我修复了它,用#!/usr/bin/ruby
替换了可执行脚本#!/usr/bin/env ruby
。