Class: YARP::HashPatternNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::HashPatternNode
- 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
-
#assocs ⇒ Object
readonly
attr_reader assocs: Array.
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#constant ⇒ Object
readonly
attr_reader constant: Node?.
-
#kwrest ⇒ Object
readonly
attr_reader kwrest: Node?.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(constant, assocs, kwrest, opening_loc, closing_loc, location) ⇒ HashPatternNode
constructor
def initialize: (constant: Node?, assocs: Array, kwrest: Node?, opening_loc: Location?, closing_loc: Location?, location: Location) -> void.
-
#opening ⇒ Object
def opening: () -> String?.
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
#assocs ⇒ Object (readonly)
attr_reader assocs: Array
2879 2880 2881 |
# File 'lib/yarp/node.rb', line 2879 def assocs @assocs end |
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
2888 2889 2890 |
# File 'lib/yarp/node.rb', line 2888 def closing_loc @closing_loc end |
#constant ⇒ Object (readonly)
attr_reader constant: Node?
2876 2877 2878 |
# File 'lib/yarp/node.rb', line 2876 def constant @constant end |
#kwrest ⇒ Object (readonly)
attr_reader kwrest: Node?
2882 2883 2884 |
# File 'lib/yarp/node.rb', line 2882 def kwrest @kwrest end |
#opening_loc ⇒ Object (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_nodes ⇒ Object 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 |
#closing ⇒ Object
def closing: () -> String?
2925 2926 2927 |
# File 'lib/yarp/node.rb', line 2925 def closing closing_loc&.slice end |
#deconstruct_keys(keys) ⇒ Object
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 |
#opening ⇒ Object
def opening: () -> String?
2920 2921 2922 |
# File 'lib/yarp/node.rb', line 2920 def opening opening_loc&.slice end |