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



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

attr_reader closing_loc: Location



4926
4927
4928
# File 'lib/yarp/node.rb', line 4926

def closing_loc
  @closing_loc
end

#elementsObject (readonly)

attr_reader elements: Array



4923
4924
4925
# File 'lib/yarp/node.rb', line 4923

def elements
  @elements
end

#opening_locObject (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_nodesObject 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

#closingObject

def closing: () -> String



4975
4976
4977
# File 'lib/yarp/node.rb', line 4975

def closing
  closing_loc.slice
end

#comment_targetsObject

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

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



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

#openingObject

def opening: () -> String



4970
4971
4972
# File 'lib/yarp/node.rb', line 4970

def opening
  opening_loc.slice
end