Class: SyntaxTree::LBracket
Overview
LBracket represents the use of a left bracket, i.e., [.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the left bracket.
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 LBracket is a child of another node. This means it’s required at initialization time. To make it easier to create LBracket 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:) ⇒ LBracket
constructor
A new instance of LBracket.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ LBracket
Returns a new instance of LBracket.
7267 7268 7269 7270 7271 |
# File 'lib/syntax_tree/node.rb', line 7267 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
7265 7266 7267 |
# File 'lib/syntax_tree/node.rb', line 7265 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the left bracket
7262 7263 7264 |
# File 'lib/syntax_tree/node.rb', line 7262 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 LBracket is a child of another node. This means it’s required at initialization time. To make it easier to create LBracket nodes without any specific value, this method provides a default node.
7311 7312 7313 |
# File 'lib/syntax_tree/node.rb', line 7311 def self.default new(value: "[", location: Location.default) end |
Instance Method Details
#===(other) ⇒ Object
7302 7303 7304 |
# File 'lib/syntax_tree/node.rb', line 7302 def ===(other) other.is_a?(LBracket) && value === other.value end |
#accept(visitor) ⇒ Object
7273 7274 7275 |
# File 'lib/syntax_tree/node.rb', line 7273 def accept(visitor) visitor.visit_lbracket(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7277 7278 7279 |
# File 'lib/syntax_tree/node.rb', line 7277 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 |
# File 'lib/syntax_tree/node.rb', line 7281 def copy(value: nil, location: nil) node = LBracket.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7294 7295 7296 |
# File 'lib/syntax_tree/node.rb', line 7294 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7298 7299 7300 |
# File 'lib/syntax_tree/node.rb', line 7298 def format(q) q.text(value) end |