Class: BracketNotation::Expression
- Inherits:
-
Object
- Object
- BracketNotation::Expression
- Defined in:
- lib/bracket_notation/expressions/expression.rb
Overview
This class represents the result of evaluating a token. It is an abstract class that should have a subclass for every possible kind of expression.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, depth = 0) ⇒ Expression
constructor
Saves the token value and optional tree depth.
-
#pretty_print ⇒ Object
Prints a visual representation of the syntax tree.
Constructor Details
#initialize(value, depth = 0) ⇒ Expression
Saves the token value and optional tree depth.
36 37 38 39 40 |
# File 'lib/bracket_notation/expressions/expression.rb', line 36 def initialize(value, depth = 0) @value = value @depth = depth @parent = nil end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
33 34 35 |
# File 'lib/bracket_notation/expressions/expression.rb', line 33 def depth @depth end |
#parent ⇒ Object
Returns the value of attribute parent.
33 34 35 |
# File 'lib/bracket_notation/expressions/expression.rb', line 33 def parent @parent end |
#value ⇒ Object
Returns the value of attribute value.
33 34 35 |
# File 'lib/bracket_notation/expressions/expression.rb', line 33 def value @value end |
Instance Method Details
#pretty_print ⇒ Object
Prints a visual representation of the syntax tree.
43 44 45 46 47 48 |
# File 'lib/bracket_notation/expressions/expression.rb', line 43 def pretty_print out = "" @depth.times {out << "--"} out << " " if @depth > 0 out << "#{@value}\n" end |