lib/gamefic/element.rb in gamefic-2.1.1 vs lib/gamefic/element.rb in gamefic-2.2.0
- old
+ new
@@ -5,17 +5,20 @@
# abstractions and ideas that don't have a physical presence but still might
# need to be referenced in a command.
#
class Element
include Gamefic::Describable
- # include Gamefic::Index
include Gamefic::Serialize
- # @todo It would be nice if this initialization wasn't necessary.
def initialize(args = {})
- # super self.class.default_attributes.merge(args)
- self.class.default_attributes.merge(args).each_pair do |k, v|
+ klass = self.class
+ defaults = {}
+ while klass <= Element
+ defaults = klass.default_attributes.merge(defaults)
+ klass = klass.superclass
+ end
+ defaults.merge(args).each_pair do |k, v|
public_send "#{k}=", v
end
post_initialize
yield self if block_given?
end
@@ -35,13 +38,9 @@
# A hash of default values for attributes when creating an instance.
#
# @return [Hash]
def default_attributes
@default_attributes ||= {}
- end
-
- def inherited subclass
- subclass.set_default default_attributes
end
end
end
end