Sha256: a32a6292fa3f60324ef0673b7f496389ac583097dfda80e7a6a7a59725c01613

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Mutant
  class Mutator
    class Node
      # Namespace for define mutations
      class Define < self

      private

        # Emit mutations
        #
        # @return [undefined]
        def dispatch
          emit_arguments_mutations
          emit_optarg_body_assignments
          emit_body(N_RAISE)
          emit_body(N_ZSUPER)
          emit_body(nil)
          emit_body_mutations if body
        end

        # Emit mutations with optional arguments as assignments in method
        #
        # @return [undefined]
        def emit_optarg_body_assignments
          arguments.children.each do |argument|
            next unless n_optarg?(argument) && AST::Meta::Optarg.new(argument).used?

            emit_body_prepend(s(:lvasgn, *argument))
          end
        end

        # Emit valid body ASTs depending on instance body
        #
        # @param node [Parser::AST::Node]
        #
        # @return [undefined]
        def emit_body_prepend(node)
          if body
            emit_body(s(:begin, node, body))
          else
            emit_body(node)
          end
        end

        # Mutator for instance method defines
        class Instance < self

          handle :def

          children :name, :arguments, :body

        end # Instance

        # Mutator for singleton method defines
        class Singleton < self

          handle :defs

          children :subject, :name, :arguments, :body

        end # Singleton

      end # Define
    end # Node
  end # Mutator
end # Mutant

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mutant-0.9.8 lib/mutant/mutator/node/define.rb
mutant-0.9.7 lib/mutant/mutator/node/define.rb
mutant-0.9.6 lib/mutant/mutator/node/define.rb
mutant-0.9.5 lib/mutant/mutator/node/define.rb
mutant-0.9.4 lib/mutant/mutator/node/define.rb
mutant-0.9.3 lib/mutant/mutator/node/define.rb
mutant-0.9.2 lib/mutant/mutator/node/define.rb
mutant-0.9.1 lib/mutant/mutator/node/define.rb
mutant-0.9.0 lib/mutant/mutator/node/define.rb