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, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ LBrace
Returns a new instance of LBrace.
7210 7211 7212 7213 7214 |
# File 'lib/syntax_tree/node.rb', line 7210 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
7208 7209 7210 |
# File 'lib/syntax_tree/node.rb', line 7208 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the left brace
7205 7206 7207 |
# File 'lib/syntax_tree/node.rb', line 7205 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.
7254 7255 7256 |
# File 'lib/syntax_tree/node.rb', line 7254 def self.default new(value: "{", location: Location.default) end |
Instance Method Details
#===(other) ⇒ Object
7245 7246 7247 |
# File 'lib/syntax_tree/node.rb', line 7245 def ===(other) other.is_a?(LBrace) && value === other.value end |
#accept(visitor) ⇒ Object
7216 7217 7218 |
# File 'lib/syntax_tree/node.rb', line 7216 def accept(visitor) visitor.visit_lbrace(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7220 7221 7222 |
# File 'lib/syntax_tree/node.rb', line 7220 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 |
# File 'lib/syntax_tree/node.rb', line 7224 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
7237 7238 7239 |
# File 'lib/syntax_tree/node.rb', line 7237 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7241 7242 7243 |
# File 'lib/syntax_tree/node.rb', line 7241 def format(q) q.text(value) end |