Module: Gamefic::Node
- Included in:
- Entity
- Defined in:
- lib/gamefic/node.rb
Overview
Parent/child relationships for objects.
Instance Attribute Summary collapse
-
#parent ⇒ Node?
The object’s parent.
Instance Method Summary collapse
-
#accessible? ⇒ Boolean
Determine if external objects can interact with this object’s children.
- #adjacent?(other) ⇒ Boolean
-
#children ⇒ Array<Node>
An array of the object’s children.
-
#flatten ⇒ Array<Node>
Get a flat array of all descendants.
-
#include?(other) ⇒ Boolean
True if this node is the other’s parent.
-
#take(*children) ⇒ Array<Node>
Add children to the node.
Instance Attribute Details
#parent ⇒ Node?
The object’s parent.
16 17 18 |
# File 'lib/gamefic/node.rb', line 16 def parent @parent end |
Instance Method Details
#accessible? ⇒ Boolean
Determine if external objects can interact with this object’s children. For example, a game can designate that the contents of a bowl are accessible, while the contents of a locked safe are not.
59 60 61 |
# File 'lib/gamefic/node.rb', line 59 def accessible? true end |
#adjacent?(other) ⇒ Boolean
70 71 72 |
# File 'lib/gamefic/node.rb', line 70 def adjacent?(other) other.parent == parent end |
#children ⇒ Array<Node>
An array of the object’s children.
21 22 23 |
# File 'lib/gamefic/node.rb', line 21 def children child_set.to_a.freeze end |
#flatten ⇒ Array<Node>
Get a flat array of all descendants.
28 29 30 |
# File 'lib/gamefic/node.rb', line 28 def flatten children.flat_map { |child| [child] + child.flatten } end |
#include?(other) ⇒ Boolean
True if this node is the other’s parent.
66 67 68 |
# File 'lib/gamefic/node.rb', line 66 def include?(other) other.parent == self end |