Class: Prism::YieldNode

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

Overview

Represents the use of the ‘yield` keyword.

yield 1
^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc) ⇒ YieldNode

Initialize a new YieldNode node.



16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
# File 'lib/prism/node.rb', line 16560

def initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @lparen_loc = lparen_loc
  @arguments = arguments
  @rparen_loc = rparen_loc
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



16627
16628
16629
# File 'lib/prism/node.rb', line 16627

def arguments
  @arguments
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



16668
16669
16670
# File 'lib/prism/node.rb', line 16668

def self.type
  :yield_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



16674
16675
16676
16677
16678
16679
16680
# File 'lib/prism/node.rb', line 16674

def ===(other)
  other.is_a?(YieldNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (lparen_loc.nil? == other.lparen_loc.nil?) &&
    (arguments === other.arguments) &&
    (rparen_loc.nil? == other.rparen_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



16572
16573
16574
# File 'lib/prism/node.rb', line 16572

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

#child_nodesObject Also known as: deconstruct

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



16577
16578
16579
# File 'lib/prism/node.rb', line 16577

def child_nodes
  [arguments]
end

#comment_targetsObject

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



16589
16590
16591
# File 'lib/prism/node.rb', line 16589

def comment_targets
  [keyword_loc, *lparen_loc, *arguments, *rparen_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16582
16583
16584
16585
16586
# File 'lib/prism/node.rb', line 16582

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << arguments if arguments
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?) -> YieldNode



16594
16595
16596
# File 'lib/prism/node.rb', line 16594

def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc)
  YieldNode.new(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location? }



16602
16603
16604
# File 'lib/prism/node.rb', line 16602

def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc }
end

#inspectObject

def inspect -> String



16658
16659
16660
# File 'lib/prism/node.rb', line 16658

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



16643
16644
16645
# File 'lib/prism/node.rb', line 16643

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



16607
16608
16609
16610
16611
# File 'lib/prism/node.rb', line 16607

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#lparenObject

def lparen: () -> String?



16648
16649
16650
# File 'lib/prism/node.rb', line 16648

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
# File 'lib/prism/node.rb', line 16614

def lparen_loc
  location = @lparen_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#rparenObject

def rparen: () -> String?



16653
16654
16655
# File 'lib/prism/node.rb', line 16653

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
# File 'lib/prism/node.rb', line 16630

def rparen_loc
  location = @rparen_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



16663
16664
16665
# File 'lib/prism/node.rb', line 16663

def type
  :yield_node
end