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



6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
# File 'lib/syntax_tree/node.rb', line 6132

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

  while (node = queue.shift)
    case node
    when Assign, MAssign, OpAssign
      return true
    else
      node.child_nodes.each { |child| queue << child if child }
    end
  end

  false
end