Class: WhatDyaReturn::AST::IfNode

Inherits:
RuboCop::AST::IfNode
  • Object
show all
Defined in:
lib/what_dya_return/ast/node/if_node.rb

Overview

A node extension for ‘if` nodes.

Instance Method Summary collapse

Instance Method Details

#else_branch_reachable?Boolean

Examples:


if true
  42
else
  run # unreachable
end

Returns:

  • (Boolean)


35
36
37
# File 'lib/what_dya_return/ast/node/if_node.rb', line 35

def else_branch_reachable?
  ((if? || ternary? || elsif?) && condition.truthy_literal?.!) || (unless? && condition.falsey_literal?.!)
end

#if_branch_reachable?Boolean

Examples:


if false # or `nil`
  42 # unreachable
else
  run
end

Returns:

  • (Boolean)


20
21
22
# File 'lib/what_dya_return/ast/node/if_node.rb', line 20

def if_branch_reachable?
  ((if? || ternary? || elsif?) && condition.falsey_literal?.!) || (unless? && condition.truthy_literal?.!)
end