Class: YARP::HashNode

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

Overview

Represents a hash literal.

{ a => b }
^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opening_loc, elements, closing_loc, location) ⇒ HashNode

def initialize: (opening_loc: Location, elements: Array, closing_loc: Location, location: Location) -> void



2841
2842
2843
2844
2845
2846
# File 'lib/yarp/node.rb', line 2841

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_locObject (readonly)

attr_reader closing_loc: Location



2838
2839
2840
# File 'lib/yarp/node.rb', line 2838

def closing_loc
  @closing_loc
end

#elementsObject (readonly)

attr_reader elements: Array



2835
2836
2837
# File 'lib/yarp/node.rb', line 2835

def elements
  @elements
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



2832
2833
2834
# File 'lib/yarp/node.rb', line 2832

def opening_loc
  @opening_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2849
2850
2851
# File 'lib/yarp/node.rb', line 2849

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

#child_nodesObject Also known as: deconstruct

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



2854
2855
2856
# File 'lib/yarp/node.rb', line 2854

def child_nodes
  [*elements]
end

#closingObject

def closing: () -> String



2872
2873
2874
# File 'lib/yarp/node.rb', line 2872

def closing
  closing_loc.slice
end

#deconstruct_keys(keys) ⇒ Object

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



2862
2863
2864
# File 'lib/yarp/node.rb', line 2862

def deconstruct_keys(keys)
  { opening_loc: opening_loc, elements: elements, closing_loc: closing_loc, location: location }
end

#openingObject

def opening: () -> String



2867
2868
2869
# File 'lib/yarp/node.rb', line 2867

def opening
  opening_loc.slice
end