Class: Prism::ReturnNode

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

Overview

Represents the use of the ‘return` keyword.

return 1
^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, arguments) ⇒ ReturnNode

Initialize a new ReturnNode node.



14530
14531
14532
14533
14534
14535
14536
14537
# File 'lib/prism/node.rb', line 14530

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

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



14582
14583
14584
# File 'lib/prism/node.rb', line 14582

def arguments
  @arguments
end

Class Method Details

.typeObject

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



14600
14601
14602
# File 'lib/prism/node.rb', line 14600

def self.type
  :return_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.



14606
14607
14608
14609
14610
# File 'lib/prism/node.rb', line 14606

def ===(other)
  other.is_a?(ReturnNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (arguments === other.arguments)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



14540
14541
14542
# File 'lib/prism/node.rb', line 14540

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

#child_nodesObject Also known as: deconstruct

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



14545
14546
14547
# File 'lib/prism/node.rb', line 14545

def child_nodes
  [arguments]
end

#comment_targetsObject

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



14557
14558
14559
# File 'lib/prism/node.rb', line 14557

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14550
14551
14552
14553
14554
# File 'lib/prism/node.rb', line 14550

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, arguments: self.arguments) ⇒ Object

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



14562
14563
14564
# File 'lib/prism/node.rb', line 14562

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

#deconstruct_keys(keys) ⇒ Object

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



14570
14571
14572
# File 'lib/prism/node.rb', line 14570

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

#inspectObject

def inspect -> String



14590
14591
14592
# File 'lib/prism/node.rb', line 14590

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



14585
14586
14587
# File 'lib/prism/node.rb', line 14585

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



14575
14576
14577
14578
14579
# File 'lib/prism/node.rb', line 14575

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

#typeObject

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



14595
14596
14597
# File 'lib/prism/node.rb', line 14595

def type
  :return_node
end