class Mutest::Mutator::Node::Define

Namespace for define mutations

Private Instance Methods

dispatch() click to toggle source

Emit mutations

@return [undefined]

# File lib/mutest/mutator/node/define.rb, line 11
def dispatch
  emit_arguments_mutations
  emit_optarg_body_assignments
  emit_restarg_body_mutation
  emit_body(N_RAISE)
  emit_body(N_ZSUPER)
  emit_body(nil)
  emit_body_mutations if body
end
emit_body_prepend(node) click to toggle source

Emit valid body ASTs depending on instance body

@param node [Parser::AST::Node]

@return [undefined]

# File lib/mutest/mutator/node/define.rb, line 59
def emit_body_prepend(node)
  if body
    emit_body(s(:begin, node, body))
  else
    emit_body(node)
  end
end
emit_optarg_body_assignments() click to toggle source

Emit mutations with optional arguments as assignments in method

@return [undefined]

# File lib/mutest/mutator/node/define.rb, line 24
def emit_optarg_body_assignments
  used_arguments.each do |argument|
    next unless n_optarg?(argument)

    emit_body_prepend(s(:lvasgn, *argument))
  end
end
emit_restarg_body_mutation() click to toggle source

Emit mutation with arg splat as empty array assignment in method

@return [undefined]

# File lib/mutest/mutator/node/define.rb, line 35
def emit_restarg_body_mutation
  used_arguments.each do |argument|
    replacement =
      if n_restarg?(argument)
        s(:array)
      elsif n_kwrestarg?(argument)
        s(:hash)
      end

    next unless replacement && argument.children.one?

    emit_body_prepend(s(:lvasgn, AST::Meta::Restarg.new(argument).name, replacement))
  end
end
used_arguments() click to toggle source
# File lib/mutest/mutator/node/define.rb, line 50
def used_arguments
  arguments.children.select { |arg| AST::Meta::Optarg.new(arg).used? }
end