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



2891
2892
2893
2894
2895
2896
2897
2898
# File 'lib/yarp/node.rb', line 2891

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



2879
2880
2881
# File 'lib/yarp/node.rb', line 2879

def assocs
  @assocs
end

#closing_locObject (readonly)

attr_reader closing_loc: Location?



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

def closing_loc
  @closing_loc
end

#constantObject (readonly)

attr_reader constant: Node?



2876
2877
2878
# File 'lib/yarp/node.rb', line 2876

def constant
  @constant
end

#kwrestObject (readonly)

attr_reader kwrest: Node?



2882
2883
2884
# File 'lib/yarp/node.rb', line 2882

def kwrest
  @kwrest
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



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

def opening_loc
  @opening_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2901
2902
2903
# File 'lib/yarp/node.rb', line 2901

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

#child_nodesObject Also known as: deconstruct

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



2907
2908
2909
# File 'lib/yarp/node.rb', line 2907

def child_nodes
  [constant, *assocs, kwrest]
end

#closingObject

def closing: () -> String?



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

def closing
  closing_loc&.slice
end

#deconstruct_keys(keys) ⇒ Object

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



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

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?



2920
2921
2922
# File 'lib/yarp/node.rb', line 2920

def opening
  opening_loc&.slice
end