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



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

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



2827
2828
2829
# File 'lib/yarp/node.rb', line 2827

def closing_loc
  @closing_loc
end

#elementsObject (readonly)

attr_reader elements: Array



2824
2825
2826
# File 'lib/yarp/node.rb', line 2824

def elements
  @elements
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



2821
2822
2823
# File 'lib/yarp/node.rb', line 2821

def opening_loc
  @opening_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



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

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

#child_nodesObject Also known as: deconstruct

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



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

def child_nodes
  [*elements]
end

#closingObject

def closing: () -> String



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

def closing
  closing_loc.slice
end

#deconstruct_keys(keys) ⇒ Object

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



2852
2853
2854
# File 'lib/yarp/node.rb', line 2852

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

#openingObject

def opening: () -> String



2857
2858
2859
# File 'lib/yarp/node.rb', line 2857

def opening
  opening_loc.slice
end