Class: YARP::ArrayPatternNode

Inherits:
YARPNode
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(constant, requireds, rest, posts, opening_loc, closing_loc, location) ⇒ ArrayPatternNode

def initialize: (constant: Node?, requireds: Array, rest: Node?, posts: Array, opening_loc: Location?, closing_loc: Location?, location: Location) -> void



316
317
318
319
320
321
322
323
324
# File 'lib/yarp/node.rb', line 316

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_locObject (readonly)

attr_reader closing_loc: Location?



313
314
315
# File 'lib/yarp/node.rb', line 313

def closing_loc
  @closing_loc
end

#constantObject (readonly)

attr_reader constant: Node?



298
299
300
# File 'lib/yarp/node.rb', line 298

def constant
  @constant
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



310
311
312
# File 'lib/yarp/node.rb', line 310

def opening_loc
  @opening_loc
end

#postsObject (readonly)

attr_reader posts: Array



307
308
309
# File 'lib/yarp/node.rb', line 307

def posts
  @posts
end

#requiredsObject (readonly)

attr_reader requireds: Array



301
302
303
# File 'lib/yarp/node.rb', line 301

def requireds
  @requireds
end

#restObject (readonly)

attr_reader rest: Node?



304
305
306
# File 'lib/yarp/node.rb', line 304

def rest
  @rest
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



327
328
329
# File 'lib/yarp/node.rb', line 327

def accept(visitor)
  visitor.visit_array_pattern_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



332
333
334
# File 'lib/yarp/node.rb', line 332

def child_nodes
  [constant, *requireds, rest, *posts]
end

#closingObject

def closing: () -> String?



363
364
365
# File 'lib/yarp/node.rb', line 363

def closing
  closing_loc&.slice
end

#copy(**params) ⇒ Object

def copy: (**params) -> ArrayPatternNode



337
338
339
340
341
342
343
344
345
346
347
# File 'lib/yarp/node.rb', line 337

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

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



353
354
355
# File 'lib/yarp/node.rb', line 353

def deconstruct_keys(keys)
  { constant: constant, requireds: requireds, rest: rest, posts: posts, opening_loc: opening_loc, closing_loc: closing_loc, location: location }
end

#openingObject

def opening: () -> String?



358
359
360
# File 'lib/yarp/node.rb', line 358

def opening
  opening_loc&.slice
end