class Crispr::Mutations::Unary

Mutates unary operator expressions such as !x, -x, +x.

def mutations_for(node)

Returns:
  • (Array) - mutated nodes

Parameters:
  • node (Parser::AST::Node) -- the AST node to inspect
def mutations_for(node)
  return [] unless node.is_a?(Parser::AST::Node)
  return [] unless node.type == :send
  receiver, method_name, = node.children
  case method_name
  when :!
    [receiver].compact
  when :-@
    [Parser::AST::Node.new(:send, [receiver, :+@])]
  when :+@
    [Parser::AST::Node.new(:send, [receiver, :-@])]
  else
    []
  end
end