Class: YARP::ReturnNode

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

Overview

Represents the use of the ‘return` keyword.

return 1
^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword_loc, arguments, location) ⇒ ReturnNode

def initialize: (keyword_loc: Location, arguments: ArgumentsNode?, location: Location) -> void



9072
9073
9074
9075
9076
# File 'lib/yarp/node.rb', line 9072

def initialize(keyword_loc, arguments, location)
  @keyword_loc = keyword_loc
  @arguments = arguments
  @location = location
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



9069
9070
9071
# File 'lib/yarp/node.rb', line 9069

def arguments
  @arguments
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



9066
9067
9068
# File 'lib/yarp/node.rb', line 9066

def keyword_loc
  @keyword_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



9079
9080
9081
# File 'lib/yarp/node.rb', line 9079

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

#child_nodesObject Also known as: deconstruct

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



9084
9085
9086
# File 'lib/yarp/node.rb', line 9084

def child_nodes
  [arguments]
end

#comment_targetsObject

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



9089
9090
9091
# File 'lib/yarp/node.rb', line 9089

def comment_targets
  [keyword_loc, *arguments]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ReturnNode



9094
9095
9096
9097
9098
9099
9100
# File 'lib/yarp/node.rb', line 9094

def copy(**params)
  ReturnNode.new(
    params.fetch(:keyword_loc) { keyword_loc },
    params.fetch(:arguments) { arguments },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



9106
9107
9108
# File 'lib/yarp/node.rb', line 9106

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

#inspect(inspector = NodeInspector.new) ⇒ Object



9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
# File 'lib/yarp/node.rb', line 9115

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

#keywordObject

def keyword: () -> String



9111
9112
9113
# File 'lib/yarp/node.rb', line 9111

def keyword
  keyword_loc.slice
end