Class: WhatDyaReturn::StatementChecker::ReturnableStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/what_dya_return/statement_checker/returnable_statement.rb

Constant Summary collapse

USED_CHECKERS =

rubocop:disable Layout/HashAlignment

{
  AST::ReturnNode => :return_node_used?,
  AST::DefNode    => :def_node_used?,
  AST::BeginNode  => :begin_node_used?,
  AST::BreakNode  => :break_node_used?,
  AST::WhileNode  => :while_until_node_used?,
  AST::UntilNode  => :while_until_node_used?,
  AST::ForNode    => :for_node_used?,
  AST::BlockNode  => :block_node_used?
}.freeze

Instance Method Summary collapse

Instance Method Details

#ok?(node) ⇒ Boolean

Inspired by RuboCop::AST::Node#value_used?

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/what_dya_return/statement_checker/returnable_statement.rb', line 22

def ok?(node)
  return false if node.parent.nil?

  if (checker = USED_CHECKERS[node.parent.class])
    send(checker, node)
  else
    ok?(node.parent)
  end
end