Ich versuche, eine Klassenvariable als Hash zu initialisieren, wenn ich eine Instanz von SomeClass erstelle, aber ich bekomme immer einen Fehler. Etwas neu zu Rubin, so würde jede Hilfe geschätzt werden. DankInitialisieren einer Hash-Variablen beim Erstellen einer Instanz
class SomeClass < ActiveRecord::Base
attr_accessible :some_hash
serialize :some_hash, Hash
def initialize(args = {})
@some_hash != {}
end
end
NoMethodError: nicht definierte Methode 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‘
von /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2827:in has_attribute?'
inspizieren '
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2888:in
von /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2887:in collect'
inspizieren'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2887:in
von/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
von /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
von /opt/local/lib/ruby/1.8/irb.rb:154:in eval_input'
start '
from /opt/local/lib/ruby/1.8/irb.rb:71:in
von /opt/local/lib/ruby/1.8/irb.rb:70:in catch'
start'
from /opt/local/lib/ruby/1.8/irb.rb:70:in
aus/opt/local/bin/irb: 13