Class: Gamefic::Entity
- Inherits:
-
Object
- Object
- Gamefic::Entity
- Includes:
- Describable, Node
- Defined in:
- lib/gamefic/entity.rb
Overview
Entities are the people, places, and things that exist in a Gamefic narrative. Authors are encouraged to define Entity subclasses to create entity types that have additional features or need special handling in actions.
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Node
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.
-
.set_default(attrs = {}) ⇒ Object
Set or update the default values for new instances.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value of the property.
- #[]=(key, value) ⇒ Object
-
#initialize(**args) {|_self| ... } ⇒ Entity
constructor
include Messaging.
- #inspect ⇒ Object
-
#post_initialize ⇒ Object
This method can be overridden for additional processing after the entity has been created.
-
#session ⇒ Hash
A freeform property dictionary.
Methods included from Node
#accessible?, #children, #flatten, #has?
Methods included from Describable
default_description, default_description=, #definitely, #description, #description=, #description?, #indefinitely, #keywords, #proper_named=, #proper_named?, #to_s
Constructor Details
#initialize(**args) {|_self| ... } ⇒ Entity
include Messaging
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gamefic/entity.rb', line 14 def initialize **args klass = self.class defaults = {} while klass <= Entity defaults = klass.default_attributes.merge(defaults) klass = klass.superclass end defaults.merge(args).each_pair { |k, v| send "#{k}=", v } yield(self) if block_given? post_initialize end |
Class Method Details
.default_attributes ⇒ Hash
A hash of default values for attributes when creating an instance.
70 71 72 |
# File 'lib/gamefic/entity.rb', line 70 def default_attributes @default_attributes ||= {} end |
.set_default(attrs = {}) ⇒ Object
Set or update the default values for new instances.
63 64 65 |
# File 'lib/gamefic/entity.rb', line 63 def set_default attrs = {} default_attributes.merge! attrs end |
Instance Method Details
#[](key) ⇒ Object
Returns The value of the property.
45 46 47 |
# File 'lib/gamefic/entity.rb', line 45 def [](key) session[key] end |
#[]=(key, value) ⇒ Object
51 52 53 |
# File 'lib/gamefic/entity.rb', line 51 def []=(key, value) session[key] = value end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/gamefic/entity.rb', line 55 def inspect "#<#{self.class} #{name}>" end |
#post_initialize ⇒ Object
This method can be overridden for additional processing after the entity has been created.
31 |
# File 'lib/gamefic/entity.rb', line 31 def post_initialize; end |
#session ⇒ Hash
A freeform property dictionary. Authors can use the session hash to assign custom properties to the entity. It can also be referenced directly using [] without the method name, e.g., entity.session or entity.
39 40 41 |
# File 'lib/gamefic/entity.rb', line 39 def session @session ||= {} end |