Class: SyntaxTree::Op
- Inherits:
-
Object
- Object
- SyntaxTree::Op
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the operator.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Op
constructor
A new instance of Op.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Op
Returns a new instance of Op.
8815 8816 8817 8818 8819 |
# File 'lib/syntax_tree.rb', line 8815 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
8813 8814 8815 |
# File 'lib/syntax_tree.rb', line 8813 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8810 8811 8812 |
# File 'lib/syntax_tree.rb', line 8810 def location @location end |
#value ⇒ Object (readonly)
- String
-
the operator
8807 8808 8809 |
# File 'lib/syntax_tree.rb', line 8807 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8821 8822 8823 |
# File 'lib/syntax_tree.rb', line 8821 def child_nodes [] end |
#format(q) ⇒ Object
8825 8826 8827 |
# File 'lib/syntax_tree.rb', line 8825 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 |
# File 'lib/syntax_tree.rb', line 8829 def pretty_print(q) q.group(2, "(", ")") do q.text("op") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8840 8841 8842 |
# File 'lib/syntax_tree.rb', line 8840 def to_json(*opts) { type: :op, value: value, loc: location, cmts: comments }.to_json(*opts) end |