Class: Evilution::Mutator::Operator::LastExpressionRemoval Private
- Inherits:
-
Base
- Object
- Prism::Visitor
- Base
- Evilution::Mutator::Operator::LastExpressionRemoval
- Defined in:
- lib/evilution/mutator/operator/last_expression_removal.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Removes a trailing literal expression (true/false/nil/integer/symbol) from
a method body. Targets the idiomatic Ruby pattern def foo?; side_effect; true; end where the explicit literal return value is the high-signal
behavior under test — dropping it makes the method return whatever the
preceding statement evaluates to. Strong against predicates and
command-query split methods.
Constant Summary collapse
- LITERAL_NODE_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ Prism::TrueNode, Prism::FalseNode, Prism::NilNode, Prism::IntegerNode, Prism::SymbolNode ].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #visit_def_node(node) ⇒ Object private
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_def_node(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/evilution/mutator/operator/last_expression_removal.rb', line 20 def visit_def_node(node) last_literal = trailing_literal(node) if last_literal add_mutation( offset: last_literal.location.start_offset, length: last_literal.location.length, replacement: "", node: last_literal ) end super end |