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 attributes when creating an instance.
-
.set_default(**attrs) ⇒ Object
Set or update the default attributes for new instances.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value of the property.
- #[]=(key, value) ⇒ Object
-
#initialize(**args) {|_self| ... } ⇒ Entity
constructor
A new instance of Entity.
- #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
Returns a new instance of Entity.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gamefic/entity.rb', line 13 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 attributes when creating an instance.
68 69 70 |
# File 'lib/gamefic/entity.rb', line 68 def default_attributes @default_attributes ||= {} end |
.set_default(**attrs) ⇒ Object
Set or update the default attributes for new instances.
61 62 63 |
# File 'lib/gamefic/entity.rb', line 61 def set_default **attrs default_attributes.merge! attrs end |
Instance Method Details
#[](key) ⇒ Object
Returns The value of the property.
44 45 46 |
# File 'lib/gamefic/entity.rb', line 44 def [](key) session[key] end |
#[]=(key, value) ⇒ Object
50 51 52 |
# File 'lib/gamefic/entity.rb', line 50 def []=(key, value) session[key] = value end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/gamefic/entity.rb', line 54 def inspect "#<#{self.class} #{name}>" end |
#post_initialize ⇒ Object
This method can be overridden for additional processing after the entity has been created.
30 |
# File 'lib/gamefic/entity.rb', line 30 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.
38 39 40 |
# File 'lib/gamefic/entity.rb', line 38 def session @session ||= {} end |