Class: Evilution::Mutator::Operator::ReceiverReplacement

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/receiver_replacement.rb

Constant Summary collapse

RUBY_RESERVED_KEYWORDS =

Ruby reserved words. A call like ‘self.class` — when stripped of its `self.` receiver — becomes the bare token `class`, which the parser reads as the class-definition keyword rather than a method call. Producing this mutation guarantees an unparseable result. Skip when the call’s method name collides with any reserved keyword.

%i[
  BEGIN END __ENCODING__ __FILE__ __LINE__
  alias and begin break case class def defined? do else elsif end
  ensure false for if in module next nil not or redo rescue retry
  return self super then true undef unless until when while yield
].to_set.freeze

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

#call, clear_parse_cache!, #initialize, operator_name, parsed_tree_for

Constructor Details

This class inherits a constructor from Evilution::Mutator::Base

Instance Method Details

#visit_call_node(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/evilution/mutator/operator/receiver_replacement.rb', line 18

def visit_call_node(node)
  if eligible_self_call?(node)
    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: call_without_self_text(node),
      node: node
    )
  end

  super
end