Class: BracketTree::Node
- Inherits:
-
Object
- Object
- BracketTree::Node
- Defined in:
- lib/bracket_tree/node.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#position ⇒ Object
Returns the value of attribute position.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(position, payload = nil) ⇒ Node
constructor
A new instance of Node.
- #method_missing(sym, *args, &block) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(position, payload = nil) ⇒ Node
Returns a new instance of Node.
5 6 7 8 |
# File 'lib/bracket_tree/node.rb', line 5 def initialize position, payload = nil @position = position @payload = payload end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
10 11 12 |
# File 'lib/bracket_tree/node.rb', line 10 def method_missing(sym, *args, &block) @payload.send sym, *args, &block end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
3 4 5 |
# File 'lib/bracket_tree/node.rb', line 3 def left @left end |
#payload ⇒ Object
Returns the value of attribute payload.
3 4 5 |
# File 'lib/bracket_tree/node.rb', line 3 def payload @payload end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/bracket_tree/node.rb', line 3 def position @position end |
#right ⇒ Object
Returns the value of attribute right.
3 4 5 |
# File 'lib/bracket_tree/node.rb', line 3 def right @right end |
Instance Method Details
#to_h ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/bracket_tree/node.rb', line 14 def to_h { position: @position, payload: @payload, left: @left ? @left.to_h : nil, right: @right ? @right.to_h : nil } end |