Class: YARP::AssocSplatNode

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

Overview

Represents a splat in a hash literal.

{ **foo }
  ^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, operator_loc, location) ⇒ AssocSplatNode

def initialize: (value: Node?, operator_loc: Location, location: Location) -> void



550
551
552
553
554
# File 'lib/yarp/node.rb', line 550

def initialize(value, operator_loc, location)
  @value = value
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



547
548
549
# File 'lib/yarp/node.rb', line 547

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node?



544
545
546
# File 'lib/yarp/node.rb', line 544

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



557
558
559
# File 'lib/yarp/node.rb', line 557

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

#child_nodesObject Also known as: deconstruct

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



562
563
564
# File 'lib/yarp/node.rb', line 562

def child_nodes
  [value]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



567
568
569
# File 'lib/yarp/node.rb', line 567

def comment_targets
  [*value, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> AssocSplatNode



572
573
574
575
576
577
578
# File 'lib/yarp/node.rb', line 572

def copy(**params)
  AssocSplatNode.new(
    params.fetch(:value) { value },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



584
585
586
# File 'lib/yarp/node.rb', line 584

def deconstruct_keys(keys)
  { value: value, operator_loc: operator_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



593
594
595
596
597
598
599
600
601
602
603
# File 'lib/yarp/node.rb', line 593

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (value = self.value).nil?
    inspector << "├── value: ∅\n"
  else
    inspector << "├── value:\n"
    inspector << value.inspect(inspector.child_inspector("")).delete_prefix(inspector.prefix)
  end
  inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String



589
590
591
# File 'lib/yarp/node.rb', line 589

def operator
  operator_loc.slice
end