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 yarp/node.rb, line 5088 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 yarp/node.rb, line 5098 def accept(visitor) visitor.visit_hash_pattern_node(self) end
child_nodes()
click to toggle source
def child_nodes
: () -> Array[nil | Node]
# File yarp/node.rb, line 5103 def child_nodes [constant, *assocs, kwrest] end
Also aliased as: deconstruct
closing()
click to toggle source
def closing: () -> String?
# File yarp/node.rb, line 5138 def closing closing_loc&.slice end
comment_targets()
click to toggle source
def comment_targets
: () -> Array[Node | Location]
# File yarp/node.rb, line 5108 def comment_targets [*constant, *assocs, *kwrest, *opening_loc, *closing_loc] end
copy(**params)
click to toggle source
def copy: (**params) -> HashPatternNode
# File yarp/node.rb, line 5113 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
inspect(inspector = NodeInspector.new)
click to toggle source
# File yarp/node.rb, line 5142 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 yarp/node.rb, line 5133 def opening opening_loc&.slice end