Class: YARP::HashNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::HashNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a hash literal.
{ a => b }
^^^^^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location.
-
#elements ⇒ Object
readonly
attr_reader elements: Array.
-
#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) -> HashNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_loc, elements, closing_loc, location) ⇒ HashNode
constructor
def initialize: (opening_loc: Location, elements: Array, closing_loc: Location, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String.
Constructor Details
#initialize(opening_loc, elements, closing_loc, location) ⇒ HashNode
def initialize: (opening_loc: Location, elements: Array, closing_loc: Location, location: Location) -> void
4929 4930 4931 4932 4933 4934 |
# File 'lib/yarp/node.rb', line 4929 def initialize(opening_loc, elements, closing_loc, location) @opening_loc = opening_loc @elements = elements @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location
4926 4927 4928 |
# File 'lib/yarp/node.rb', line 4926 def closing_loc @closing_loc end |
#elements ⇒ Object (readonly)
attr_reader elements: Array
4923 4924 4925 |
# File 'lib/yarp/node.rb', line 4923 def elements @elements end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location
4920 4921 4922 |
# File 'lib/yarp/node.rb', line 4920 def opening_loc @opening_loc end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
4937 4938 4939 |
# File 'lib/yarp/node.rb', line 4937 def accept(visitor) visitor.visit_hash_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
4942 4943 4944 |
# File 'lib/yarp/node.rb', line 4942 def child_nodes [*elements] end |
#closing ⇒ Object
def closing: () -> String
4975 4976 4977 |
# File 'lib/yarp/node.rb', line 4975 def closing closing_loc.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4947 4948 4949 |
# File 'lib/yarp/node.rb', line 4947 def comment_targets [opening_loc, *elements, closing_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> HashNode
4952 4953 4954 4955 4956 4957 4958 4959 |
# File 'lib/yarp/node.rb', line 4952 def copy(**params) HashNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:elements) { elements }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
4965 4966 4967 |
# File 'lib/yarp/node.rb', line 4965 def deconstruct_keys(keys) { opening_loc: opening_loc, elements: elements, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
4979 4980 4981 4982 4983 4984 4985 |
# File 'lib/yarp/node.rb', line 4979 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "├── elements: #{inspector.list("#{inspector.prefix}│ ", elements)}" inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String
4970 4971 4972 |
# File 'lib/yarp/node.rb', line 4970 def opening opening_loc.slice end |