Class: YARP::ArrayPatternNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::ArrayPatternNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents an array pattern in pattern matching.
foo in 1, 2
^^^^^^^^^^^
foo in [1, 2]
^^^^^^^^^^^^^
foo in *1
^^^^^^^^^
foo in Bar[]
^^^^^^^^^^^^
foo in Bar[1, 2, 3]
^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#constant ⇒ Object
readonly
attr_reader constant: Node?.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location?.
-
#posts ⇒ Object
readonly
attr_reader posts: Array.
-
#requireds ⇒ Object
readonly
attr_reader requireds: Array.
-
#rest ⇒ Object
readonly
attr_reader rest: Node?.
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) -> ArrayPatternNode.
- #deconstruct_keys(keys) ⇒ Object
- #initialize(constant, requireds, rest, posts, opening_loc, closing_loc, location) ⇒ ArrayPatternNode constructor
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String?.
Constructor Details
#initialize(constant, requireds, rest, posts, opening_loc, closing_loc, location) ⇒ ArrayPatternNode
385 386 387 388 389 390 391 392 393 |
# File 'lib/yarp/node.rb', line 385 def initialize(constant, requireds, rest, posts, opening_loc, closing_loc, location) @constant = constant @requireds = requireds @rest = rest @posts = posts @opening_loc = opening_loc @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
382 383 384 |
# File 'lib/yarp/node.rb', line 382 def closing_loc @closing_loc end |
#constant ⇒ Object (readonly)
attr_reader constant: Node?
367 368 369 |
# File 'lib/yarp/node.rb', line 367 def constant @constant end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
379 380 381 |
# File 'lib/yarp/node.rb', line 379 def opening_loc @opening_loc end |
#posts ⇒ Object (readonly)
attr_reader posts: Array
376 377 378 |
# File 'lib/yarp/node.rb', line 376 def posts @posts end |
#requireds ⇒ Object (readonly)
attr_reader requireds: Array
370 371 372 |
# File 'lib/yarp/node.rb', line 370 def requireds @requireds end |
#rest ⇒ Object (readonly)
attr_reader rest: Node?
373 374 375 |
# File 'lib/yarp/node.rb', line 373 def rest @rest end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
396 397 398 |
# File 'lib/yarp/node.rb', line 396 def accept(visitor) visitor.visit_array_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
401 402 403 |
# File 'lib/yarp/node.rb', line 401 def child_nodes [constant, *requireds, rest, *posts] end |
#closing ⇒ Object
def closing: () -> String?
437 438 439 |
# File 'lib/yarp/node.rb', line 437 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
406 407 408 |
# File 'lib/yarp/node.rb', line 406 def comment_targets [*constant, *requireds, *rest, *posts, *opening_loc, *closing_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> ArrayPatternNode
411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/yarp/node.rb', line 411 def copy(**params) ArrayPatternNode.new( params.fetch(:constant) { constant }, params.fetch(:requireds) { requireds }, params.fetch(:rest) { rest }, params.fetch(:posts) { posts }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
427 428 429 |
# File 'lib/yarp/node.rb', line 427 def deconstruct_keys(keys) { constant: constant, requireds: requireds, rest: rest, posts: posts, opening_loc: opening_loc, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/yarp/node.rb', line 441 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) if (constant = self.constant).nil? inspector << "├── constant: ∅\n" else inspector << "├── constant:\n" inspector << constant.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── requireds: #{inspector.list("#{inspector.prefix}│ ", requireds)}" if (rest = self.rest).nil? inspector << "├── rest: ∅\n" else inspector << "├── rest:\n" inspector << rest.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── posts: #{inspector.list("#{inspector.prefix}│ ", posts)}" 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?
432 433 434 |
# File 'lib/yarp/node.rb', line 432 def opening opening_loc&.slice end |