class Gamefic::Element

The simplest class that can compose an object for use in a plot. Most game objects, especially tangible items in the game, should derive from the Entity class. Elements, on the other hand, can be used for abstractions and ideas that don't have a physical presence but still might need to be referenced in a command.

Public Class Methods

default_attributes() click to toggle source

A hash of default values for attributes when creating an instance.

@return [Hash]

# File lib/gamefic/element.rb, line 41
def default_attributes
  @default_attributes ||= {}
end
new(args = {}) { |self| ... } click to toggle source
# File lib/gamefic/element.rb, line 12
def initialize(args = {})
  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
set_default(attrs = {}) click to toggle source

Set or update the default values for new instances.

@param attrs [Hash] The attributes to be merged into the defaults.

# File lib/gamefic/element.rb, line 34
def set_default attrs = {}
  default_attributes.merge! attrs
end

Public Instance Methods

post_initialize() click to toggle source
# File lib/gamefic/element.rb, line 26
def post_initialize
  # raise NotImplementedError, "#{self.class} must implement post_initialize"
end