Module: Reek::AST::SexpExtensions::IfNode

Defined in:
lib/reek/ast/sexp_extensions/if.rb

Overview

Utility methods for :if nodes.

Instance Method Summary collapse

Instance Method Details

#body_nodes(type, ignoring = []) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/reek/ast/sexp_extensions/if.rb', line 33

def body_nodes(type, ignoring = [])
  children[1..].compact.flat_map do |child|
    if ignoring.include? child.type
      []
    else
      child.each_node(type, ignoring | type).to_a
    end
  end
end

#conditionReek::AST::Node

Returns the condition that is associated with a conditional node. For instance, this code

if charlie(bravo) then delta end

would be parsed into this AST:

s(:if,
  s(:send, nil, :charlie,
    s(:lvar, :bravo)),
  s(:send, nil, :delta), nil)

so in this case we would return this

s(:send, nil, :charlie,
  s(:lvar, :bravo))

as condition.

Returns:

  • (Reek::AST::Node)

    the condition that is associated with a conditional node. For instance, this code

    if charlie(bravo) then delta end
    

    would be parsed into this AST:

    s(:if,
      s(:send, nil, :charlie,
        s(:lvar, :bravo)),
      s(:send, nil, :delta), nil)
    

    so in this case we would return this

    s(:send, nil, :charlie,
      s(:lvar, :bravo))
    

    as condition.



28
29
30
# File 'lib/reek/ast/sexp_extensions/if.rb', line 28

def condition
  children.first
end