Class: SyntaxTree::Op
Overview
Op represents an operator literal in the source.
1 + 2
In the example above, the Op node represents the + operator.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the operator.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Op
constructor
A new instance of Op.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Op
Returns a new instance of Op.
6517 6518 6519 6520 6521 |
# File 'lib/syntax_tree/node.rb', line 6517 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6515 6516 6517 |
# File 'lib/syntax_tree/node.rb', line 6515 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the operator
6512 6513 6514 |
# File 'lib/syntax_tree/node.rb', line 6512 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
6523 6524 6525 |
# File 'lib/syntax_tree/node.rb', line 6523 def accept(visitor) visitor.visit_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6527 6528 6529 |
# File 'lib/syntax_tree/node.rb', line 6527 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
6533 6534 6535 |
# File 'lib/syntax_tree/node.rb', line 6533 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6537 6538 6539 |
# File 'lib/syntax_tree/node.rb', line 6537 def format(q) q.text(value) end |