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?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> HashPatternNode.
- #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.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#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
5012 5013 5014 5015 5016 5017 5018 5019 |
# File 'lib/yarp/node.rb', line 5012 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
5000 5001 5002 |
# File 'lib/yarp/node.rb', line 5000 def assocs @assocs end |
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
5009 5010 5011 |
# File 'lib/yarp/node.rb', line 5009 def closing_loc @closing_loc end |
#constant ⇒ Object (readonly)
attr_reader constant: Node?
4997 4998 4999 |
# File 'lib/yarp/node.rb', line 4997 def constant @constant end |
#kwrest ⇒ Object (readonly)
attr_reader kwrest: Node?
5003 5004 5005 |
# File 'lib/yarp/node.rb', line 5003 def kwrest @kwrest end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
5006 5007 5008 |
# File 'lib/yarp/node.rb', line 5006 def opening_loc @opening_loc end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
5022 5023 5024 |
# File 'lib/yarp/node.rb', line 5022 def accept(visitor) visitor.visit_hash_pattern_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
5027 5028 5029 |
# File 'lib/yarp/node.rb', line 5027 def child_nodes [constant, *assocs, kwrest] end |
#closing ⇒ Object
def closing: () -> String?
5062 5063 5064 |
# File 'lib/yarp/node.rb', line 5062 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
5032 5033 5034 |
# File 'lib/yarp/node.rb', line 5032 def comment_targets [*constant, *assocs, *kwrest, *opening_loc, *closing_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> HashPatternNode
5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 |
# File 'lib/yarp/node.rb', line 5037 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) ⇒ Object
5052 5053 5054 |
# File 'lib/yarp/node.rb', line 5052 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) ⇒ Object
5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 |
# File 'lib/yarp/node.rb', line 5066 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 ⇒ Object
def opening: () -> String?
5057 5058 5059 |
# File 'lib/yarp/node.rb', line 5057 def opening opening_loc&.slice end |