Class: YARP::ArrayNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::ArrayNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
[1, 2, 3]
^^^^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#elements ⇒ Object
readonly
attr_reader elements: Array.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> ArrayNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(elements, opening_loc, closing_loc, location) ⇒ ArrayNode
constructor
def initialize: (elements: Array, opening_loc: Location?, closing_loc: Location?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String?.
Constructor Details
#initialize(elements, opening_loc, closing_loc, location) ⇒ ArrayNode
def initialize: (elements: Array, opening_loc: Location?, closing_loc: Location?, location: Location) -> void
290 291 292 293 294 295 |
# File 'lib/yarp/node.rb', line 290 def initialize(elements, opening_loc, closing_loc, location) @elements = elements @opening_loc = opening_loc @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
287 288 289 |
# File 'lib/yarp/node.rb', line 287 def closing_loc @closing_loc end |
#elements ⇒ Object (readonly)
attr_reader elements: Array
281 282 283 |
# File 'lib/yarp/node.rb', line 281 def elements @elements end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
284 285 286 |
# File 'lib/yarp/node.rb', line 284 def opening_loc @opening_loc end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
298 299 300 |
# File 'lib/yarp/node.rb', line 298 def accept(visitor) visitor.visit_array_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
303 304 305 |
# File 'lib/yarp/node.rb', line 303 def child_nodes [*elements] end |
#closing ⇒ Object
def closing: () -> String?
336 337 338 |
# File 'lib/yarp/node.rb', line 336 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
308 309 310 |
# File 'lib/yarp/node.rb', line 308 def comment_targets [*elements, *opening_loc, *closing_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> ArrayNode
313 314 315 316 317 318 319 320 |
# File 'lib/yarp/node.rb', line 313 def copy(**params) ArrayNode.new( params.fetch(:elements) { elements }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
326 327 328 |
# File 'lib/yarp/node.rb', line 326 def deconstruct_keys(keys) { elements: elements, opening_loc: opening_loc, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
340 341 342 343 344 345 346 |
# File 'lib/yarp/node.rb', line 340 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── elements: #{inspector.list("#{inspector.prefix}│ ", elements)}" inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String?
331 332 333 |
# File 'lib/yarp/node.rb', line 331 def opening opening_loc&.slice end |