Class: YARP::HashPatternNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents a hash pattern in pattern matching.

foo => { a: 1, b: 2 }
       ^^^^^^^^^^^^^^

foo => { a: 1, b: 2, **c }
       ^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(constant, assocs, kwrest, opening_loc, closing_loc, location) ⇒ HashPatternNode

def initialize: (constant: Node?, assocs: Array, kwrest: Node?, opening_loc: Location?, closing_loc: Location?, location: Location) -> void



2901
2902
2903
2904
2905
2906
2907
2908
# File 'lib/yarp/node.rb', line 2901

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

Instance Attribute Details

#assocsObject (readonly)

attr_reader assocs: Array



2889
2890
2891
# File 'lib/yarp/node.rb', line 2889

def assocs
  @assocs
end

#closing_locObject (readonly)

attr_reader closing_loc: Location?



2898
2899
2900
# File 'lib/yarp/node.rb', line 2898

def closing_loc
  @closing_loc
end

#constantObject (readonly)

attr_reader constant: Node?



2886
2887
2888
# File 'lib/yarp/node.rb', line 2886

def constant
  @constant
end

#kwrestObject (readonly)

attr_reader kwrest: Node?



2892
2893
2894
# File 'lib/yarp/node.rb', line 2892

def kwrest
  @kwrest
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



2895
2896
2897
# File 'lib/yarp/node.rb', line 2895

def opening_loc
  @opening_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2911
2912
2913
# File 'lib/yarp/node.rb', line 2911

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

#child_nodesObject Also known as: deconstruct

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



2916
2917
2918
# File 'lib/yarp/node.rb', line 2916

def child_nodes
  [constant, *assocs, kwrest]
end

#closingObject

def closing: () -> String?



2934
2935
2936
# File 'lib/yarp/node.rb', line 2934

def closing
  closing_loc&.slice
end

#deconstruct_keys(keys) ⇒ Object

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



2924
2925
2926
# File 'lib/yarp/node.rb', line 2924

def deconstruct_keys(keys)
  { constant: constant, assocs: assocs, kwrest: kwrest, opening_loc: opening_loc, closing_loc: closing_loc, location: location }
end

#openingObject

def opening: () -> String?



2929
2930
2931
# File 'lib/yarp/node.rb', line 2929

def opening
  opening_loc&.slice
end