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.
8270 8271 8272 8273 8274 |
# File 'lib/syntax_tree.rb', line 8270 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
8268 8269 8270 |
# File 'lib/syntax_tree.rb', line 8268 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8265 8266 8267 |
# File 'lib/syntax_tree.rb', line 8265 def location @location end |
#value ⇒ Object (readonly)
- String
-
the operator
8262 8263 8264 |
# File 'lib/syntax_tree.rb', line 8262 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8276 8277 8278 |
# File 'lib/syntax_tree.rb', line 8276 def child_nodes [] end |
#format(q) ⇒ Object
8280 8281 8282 |
# File 'lib/syntax_tree.rb', line 8280 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 |
# File 'lib/syntax_tree.rb', line 8284 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
8295 8296 8297 |
# File 'lib/syntax_tree.rb', line 8295 def to_json(*opts) { type: :op, value: value, loc: location, cmts: comments }.to_json(*opts) end |