Class: SyntaxTree::LParen
Overview
LParen represents the use of a left parenthesis, i.e., (.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the left parenthesis.
Attributes inherited from Node
Class Method Summary collapse
-
.default ⇒ Object
Because some nodes keep around a ( token so that comments can be attached to it if they occur in the source, oftentimes an LParen is a child of another node. This means it’s required at initialization time. To make it easier to create LParen nodes without any specific value, this method provides a default node..
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ LParen
constructor
A new instance of LParen.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ LParen
Returns a new instance of LParen.
7336 7337 7338 7339 7340 |
# File 'lib/syntax_tree/node.rb', line 7336 def initialize(value:, location:) @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7334 7335 7336 |
# File 'lib/syntax_tree/node.rb', line 7334 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the left parenthesis
7331 7332 7333 |
# File 'lib/syntax_tree/node.rb', line 7331 def value @value end |
Class Method Details
.default ⇒ Object
Because some nodes keep around a ( token so that comments can be attached to it if they occur in the source, oftentimes an LParen is a child of another node. This means it’s required at initialization time. To make it easier to create LParen nodes without any specific value, this method provides a default node.
7380 7381 7382 |
# File 'lib/syntax_tree/node.rb', line 7380 def self.default new(value: "(", location: Location.default) end |
Instance Method Details
#===(other) ⇒ Object
7371 7372 7373 |
# File 'lib/syntax_tree/node.rb', line 7371 def ===(other) other.is_a?(LParen) && value === other.value end |
#accept(visitor) ⇒ Object
7342 7343 7344 |
# File 'lib/syntax_tree/node.rb', line 7342 def accept(visitor) visitor.visit_lparen(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7346 7347 7348 |
# File 'lib/syntax_tree/node.rb', line 7346 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 |
# File 'lib/syntax_tree/node.rb', line 7350 def copy(value: nil, location: nil) node = LParen.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7363 7364 7365 |
# File 'lib/syntax_tree/node.rb', line 7363 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7367 7368 7369 |
# File 'lib/syntax_tree/node.rb', line 7367 def format(q) q.text(value) end |