Module: SyntaxTree::ContainsAssignment

Defined in:
lib/syntax_tree/node.rb

Overview

If the predicate of a conditional or loop contains an assignment (in which case we can’t know for certain that that assignment doesn’t impact the statements inside the conditional) then we can’t use the modifier form and we must use the block form.

Class Method Summary collapse

Class Method Details

.call(parent) ⇒ Object



5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
# File 'lib/syntax_tree/node.rb', line 5175

def self.call(parent)
  queue = [parent]

  while (node = queue.shift)
    return true if [Assign, MAssign, OpAssign].include?(node.class)
    queue += node.child_nodes.compact
  end

  false
end