class Crispr::Mutations::Range

Applies mutations such as flipping range type, replacing with nil, and swapping bounds.
Mutation class for handling Ruby range expressions (inclusive and exclusive).

def mutations_for(node)

Returns:
  • (Array) - mutated AST nodes

Parameters:
  • node (Parser::AST::Node) -- the AST node representing a range
def mutations_for(node)
  return [] unless %i[irange erange].include?(node.type)
  left, right = node.children
  mutations = []
  # Flip the range type (inclusive <-> exclusive)
  flipped_type = node.type == :irange ? :erange : :irange
  mutations << s(flipped_type, left, right)
  # Replace with nil
  mutations << s(:nil)
  # Swap bounds if both sides are literals
  mutations << s(node.type, right, left) if left&.type == :int && right&.type == :int
  mutations
end