Class: Gamefic::Element

Inherits:
Object show all
Includes:
Describable, Index
Defined in:
lib/gamefic/element.rb

Overview

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.

Direct Known Subclasses

Entity

Constant Summary

Constants included from Keywords

Keywords::SPLIT_REGEXP

Instance Attribute Summary

Attributes included from Describable

#definite_article, #indefinite_article, #name, #synonyms

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Index

clear, #destroy, elements, from_serial, serials, stick, stuck, stuck?, #to_serial, unserialize

Methods included from Describable

default_description, default_description=, #definitely, #description, #description=, #has_description?, #indefinitely, #keywords, #proper_named=, #proper_named?, #to_s

Methods included from Keywords

#keywords, #specified?

Constructor Details

#initialize(args = {}) {|_self| ... } ⇒ Element

TODO:

It would be nice if this initialization wasn’t necessary.

Returns a new instance of Element.

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
17
# File 'lib/gamefic/element.rb', line 13

def initialize(args = {})
  super self.class.default_attributes.merge(args)
  post_initialize
  yield self if block_given?
end

Class Method Details

.default_attributesHash

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

Returns:



34
35
36
# File 'lib/gamefic/element.rb', line 34

def default_attributes
  @default_attributes ||= {}
end

.inherited(subclass) ⇒ Object



38
39
40
# File 'lib/gamefic/element.rb', line 38

def inherited subclass
  subclass.set_default default_attributes
end

.set_default(attrs = {}) ⇒ Object

Set or update the default values for new instances.

Parameters:

  • attrs (Hash) (defaults to: {})

    The attributes to be merged into the defaults.



27
28
29
# File 'lib/gamefic/element.rb', line 27

def set_default attrs = {}
  default_attributes.merge! attrs
end

Instance Method Details

#post_initializeObject



19
20
21
# File 'lib/gamefic/element.rb', line 19

def post_initialize
  # raise NotImplementedError, "#{self.class} must implement post_initialize"

end