Class: SyntaxTree::LBrace
Overview
LBrace represents the use of a left brace, i.e., {.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the left brace.
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 LBrace is a child of another node. This means it’s required at initialization time. To make it easier to create LBrace 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:) ⇒ LBrace
constructor
A new instance of LBrace.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ LBrace
Returns a new instance of LBrace.
7323 7324 7325 7326 7327 |
# File 'lib/syntax_tree/node.rb', line 7323 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
7321 7322 7323 |
# File 'lib/syntax_tree/node.rb', line 7321 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the left brace
7318 7319 7320 |
# File 'lib/syntax_tree/node.rb', line 7318 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 LBrace is a child of another node. This means it’s required at initialization time. To make it easier to create LBrace nodes without any specific value, this method provides a default node.
7367 7368 7369 |
# File 'lib/syntax_tree/node.rb', line 7367 def self.default new(value: "{", location: Location.default) end |
Instance Method Details
#===(other) ⇒ Object
7358 7359 7360 |
# File 'lib/syntax_tree/node.rb', line 7358 def ===(other) other.is_a?(LBrace) && value === other.value end |
#accept(visitor) ⇒ Object
7329 7330 7331 |
# File 'lib/syntax_tree/node.rb', line 7329 def accept(visitor) visitor.visit_lbrace(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7333 7334 7335 |
# File 'lib/syntax_tree/node.rb', line 7333 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 |
# File 'lib/syntax_tree/node.rb', line 7337 def copy(value: nil, location: nil) node = LBrace.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7350 7351 7352 |
# File 'lib/syntax_tree/node.rb', line 7350 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7354 7355 7356 |
# File 'lib/syntax_tree/node.rb', line 7354 def format(q) q.text(value) end |