Module: Solargraph::Source::NodeMethods::DeepInference

Defined in:
lib/solargraph/source/node_methods.rb

Constant Summary collapse

CONDITIONAL =
[:if, :unless]
REDUCEABLE =
[:begin, :kwbegin]
SKIPPABLE =
[:def, :defs, :class, :sclass, :module, :block]

Class Method Summary collapse

Class Method Details

.get_return_nodes(node) ⇒ Array<Parser::AST::Node>


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/solargraph/source/node_methods.rb', line 149

def get_return_nodes node
  return [] unless node.is_a?(Parser::AST::Node)
  result = []
  if REDUCEABLE.include?(node.type)
    result.concat get_return_nodes_from_children(node)
  elsif CONDITIONAL.include?(node.type)
    result.concat reduce_to_value_nodes(node.children[1..-1])
  elsif node.type == :and || node.type == :or
    result.concat reduce_to_value_nodes(node.children)
  elsif node.type == :return
    result.concat reduce_to_value_nodes([node.children[0]])
  elsif node.type == :block
    result.concat reduce_to_value_nodes(node.children[0..-2])
  else
    result.push node
  end
  result
end