Class: Henitai::Operators::MethodChainUnwrap

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

Overview

Removes individual links from a method chain by replacing the outer send node with its receiver.

Only fires when the immediate receiver is itself a :send node, which naturally excludes block-receiver chains (list.select { }.count) and standalone calls.

Example: array.uniq.sort.first

→ array.uniq.sort  (removed .first)
→ array.uniq       (removed .sort)
→ array            (removed .uniq) — via the :uniq node

Constant Summary collapse

NODE_TYPES =
%i[send].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



21
22
23
# File 'lib/henitai/operators/method_chain_unwrap.rb', line 21

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



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

def mutate(node, subject:)
  receiver = node.children[0]
  return [] unless receiver.is_a?(Parser::AST::Node) && receiver.type == :send

  method_name = node.children[1]
  [
    build_mutant(
      subject:,
      original_node: node,
      mutated_node: receiver,
      description: "removed .#{method_name} from chain"
    )
  ]
end