Class: Henitai::Operators::UpdateOperator

Inherits:
Henitai::Operator show all
Defined in:
lib/henitai/operators/update_operator.rb

Overview

Swaps compound assignment operators with their inverses.

Covers arithmetic pairs (+=/-=, *=/=) via :op_asgn and logical pairs (||=/&&=) via :or_asgn/:and_asgn. Exponent and modulo compound assignments are intentionally excluded: they are not part of the supported swap matrix and are already covered by other operator families when appropriate.

Constant Summary collapse

NODE_TYPES =
%i[op_asgn or_asgn and_asgn].freeze
ARITHMETIC_SWAPS =
{
  :+ => :-,
  :- => :+,
  :* => :/,
  :/ => :*
}.freeze

Constants inherited from Henitai::Operator

Henitai::Operator::FULL_SET, Henitai::Operator::LIGHT_SET

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Henitai::Operator

for_set, #name

Class Method Details

.node_typesObject



23
24
25
# File 'lib/henitai/operators/update_operator.rb', line 23

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/henitai/operators/update_operator.rb', line 27

def mutate(node, subject:)
  case node.type
  when :op_asgn
    mutate_arithmetic(node, subject:)
  when :or_asgn
    mutate_logical(node, subject:, from: "||=", to: :and_asgn, to_op: "&&=")
  when :and_asgn
    mutate_logical(node, subject:, from: "&&=", to: :or_asgn, to_op: "||=")
  else
    []
  end
end