我試圖初始化一個類變量作爲哈希當我創建一個SomeClass的實例但我不斷收到錯誤。有點新紅寶石,所以任何幫助,將不勝感激。感謝創建實例時初始化一個哈希變量
class SomeClass < ActiveRecord::Base
attr_accessible :some_hash
serialize :some_hash, Hash
def initialize(args = {})
@some_hash != {}
end
end
NoMethodError:未定義的方法has_key?' for nil:NilClass from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:in
method_missing的」
從/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2827:in has_attribute?'
檢查 '
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2888:in
從/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2887:in collect'
檢查'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2887:in
從的/ opt/local/lib目錄/ruby/1.8/irb.rb:310:in output_value'
eval_input'
from /opt/local/lib/ruby/1.8/irb.rb:159:in
from /opt/local/lib/ruby/1.8/irb.rb:271:in signal_status'
eval_input'
from /opt/local/lib/ruby/1.8/irb.rb:155:in
從/opt/local/lib/ruby/1.8/irb.rb:154:in eval_input'
開始從
from /opt/local/lib/ruby/1.8/irb.rb:71:in
'從/opt/local/lib/ruby/1.8/irb.rb:70:in catch'
開始
from /opt/local/lib/ruby/1.8/irb.rb:70:in
'/opt/local/bin/irb:13