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



3585
3586
3587
3588
3589
3590
# File 'lib/yarp/node.rb', line 3585

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



3582
3583
3584
# File 'lib/yarp/node.rb', line 3582

def closing_loc
  @closing_loc
end

#elementsObject (readonly)

attr_reader elements: Array



3579
3580
3581
# File 'lib/yarp/node.rb', line 3579

def elements
  @elements
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



3576
3577
3578
# File 'lib/yarp/node.rb', line 3576

def opening_loc
  @opening_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3593
3594
3595
# File 'lib/yarp/node.rb', line 3593

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

#child_nodesObject Also known as: deconstruct

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



3598
3599
3600
# File 'lib/yarp/node.rb', line 3598

def child_nodes
  [*elements]
end

#closingObject

def closing: () -> String



3626
3627
3628
# File 'lib/yarp/node.rb', line 3626

def closing
  closing_loc.slice
end

#copy(**params) ⇒ Object

def copy: (**params) -> HashNode



3603
3604
3605
3606
3607
3608
3609
3610
# File 'lib/yarp/node.rb', line 3603

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]



3616
3617
3618
# File 'lib/yarp/node.rb', line 3616

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

#openingObject

def opening: () -> String



3621
3622
3623
# File 'lib/yarp/node.rb', line 3621

def opening
  opening_loc.slice
end