Class: Gamefic::Element
- 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
Constant Summary
Constants included from Keywords
Instance Attribute Summary
Attributes included from Describable
#definite_article, #indefinite_article, #name, #synonyms
Class Method Summary collapse
-
.default_attributes ⇒ Hash
A hash of default values for attributes when creating an instance.
- .inherited(subclass) ⇒ Object
-
.set_default(attrs = {}) ⇒ Object
Set or update the default values for new instances.
Instance Method Summary collapse
-
#initialize(args = {}) {|_self| ... } ⇒ Element
constructor
A new instance of Element.
- #post_initialize ⇒ Object
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
Constructor Details
#initialize(args = {}) {|_self| ... } ⇒ Element
It would be nice if this initialization wasn’t necessary.
Returns a new instance of Element.
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_attributes ⇒ Hash
A hash of default values for attributes when creating an instance.
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.
27 28 29 |
# File 'lib/gamefic/element.rb', line 27 def set_default attrs = {} default_attributes.merge! attrs end |
Instance Method Details
#post_initialize ⇒ Object
19 20 21 |
# File 'lib/gamefic/element.rb', line 19 def post_initialize # raise NotImplementedError, "#{self.class} must implement post_initialize" end |