class YARP::HashPatternNode
Represents a hash pattern in pattern matching.
foo => { a: 1, b: 2 } ^^^^^^^^^^^^^^ foo => { a: 1, b: 2, **c } ^^^^^^^^^^^^^^^^^^^
Attributes
assocs[R]
attr_reader assocs: Array
closing_loc[R]
attr_reader closing_loc
: Location?
constant[R]
attr_reader constant: Node?
kwrest[R]
attr_reader kwrest: Node?
opening_loc[R]
attr_reader opening_loc
: Location?
Public Class Methods
new(constant, assocs, kwrest, opening_loc, closing_loc, location)
click to toggle source
def initialize: (constant: Node?, assocs: Array, kwrest: Node?, opening_loc
: Location?, closing_loc
: Location?, location: Location) -> void
# File lib/yarp/node.rb, line 5482 def initialize(constant, assocs, kwrest, opening_loc, closing_loc, location) @constant = constant @assocs = assocs @kwrest = kwrest @opening_loc = opening_loc @closing_loc = closing_loc @location = location end
Public Instance Methods
accept(visitor)
click to toggle source
def accept: (visitor: Visitor
) -> void
# File lib/yarp/node.rb, line 5492 def accept(visitor) visitor.visit_hash_pattern_node(self) end
child_nodes()
click to toggle source
def child_nodes
: () -> Array[nil | Node]
# File lib/yarp/node.rb, line 5497 def child_nodes [constant, *assocs, kwrest] end
Also aliased as: deconstruct
closing()
click to toggle source
def closing: () -> String
?
# File lib/yarp/node.rb, line 5541 def closing closing_loc&.slice end
comment_targets()
click to toggle source
def comment_targets
: () -> Array[Node | Location]
# File lib/yarp/node.rb, line 5511 def comment_targets [*constant, *assocs, *kwrest, *opening_loc, *closing_loc] end
compact_child_nodes()
click to toggle source
def compact_child_nodes
: () -> Array
# File lib/yarp/node.rb, line 5502 def compact_child_nodes compact = [] compact << constant if constant compact.concat(assocs) compact << kwrest if kwrest compact end
copy(**params)
click to toggle source
def copy: (**params) -> HashPatternNode
# File lib/yarp/node.rb, line 5516 def copy(**params) HashPatternNode.new( params.fetch(:constant) { constant }, params.fetch(:assocs) { assocs }, params.fetch(:kwrest) { kwrest }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end
deconstruct_keys(keys)
click to toggle source
def deconstruct_keys
: (keys: Array) -> Hash[Symbol, nil | Node | Array | String
| Token | Array | Location]
# File lib/yarp/node.rb, line 5531 def deconstruct_keys(keys) { constant: constant, assocs: assocs, kwrest: kwrest, opening_loc: opening_loc, closing_loc: closing_loc, location: location } end
inspect(inspector = NodeInspector.new)
click to toggle source
# File lib/yarp/node.rb, line 5545 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 << "├── assocs: #{inspector.list("#{inspector.prefix}│ ", assocs)}" if (kwrest = self.kwrest).nil? inspector << "├── kwrest: ∅\n" else inspector << "├── kwrest:\n" inspector << kwrest.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end
opening()
click to toggle source
def opening: () -> String
?
# File lib/yarp/node.rb, line 5536 def opening opening_loc&.slice end