Class: BracketTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/bracket_tree/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#leftObject

Returns the value of attribute left.



3
4
5
# File 'lib/bracket_tree/node.rb', line 3

def left
  @left
end

#payloadObject

Returns the value of attribute payload.



3
4
5
# File 'lib/bracket_tree/node.rb', line 3

def payload
  @payload
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/bracket_tree/node.rb', line 3

def position
  @position
end

#rightObject

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_hObject



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