Class: Mutiny::Mutants::Mutant

Inherits:
Object
  • Object
show all
Defined in:
lib/mutiny/mutants/mutant.rb,
lib/mutiny/mutants/mutant/location.rb

Defined Under Namespace

Classes: Location

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject: nil, code:, mutation_name: nil, index: nil, position: nil) ⇒ Mutant

Returns a new instance of Mutant.



10
11
12
13
14
15
16
17
# File 'lib/mutiny/mutants/mutant.rb', line 10

def initialize(subject: nil, code:, mutation_name: nil, index: nil, position: nil)
  @subject = subject
  @code = code
  @mutation_name = mutation_name
  @index = index
  @stillborn = false
  @location = Location.new(position: position, content: code)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/mutiny/mutants/mutant.rb', line 6

def code
  @code
end

#indexObject

Returns the value of attribute index.



7
8
9
# File 'lib/mutiny/mutants/mutant.rb', line 7

def index
  @index
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/mutiny/mutants/mutant.rb', line 6

def location
  @location
end

#mutation_nameObject (readonly)

Returns the value of attribute mutation_name.



6
7
8
# File 'lib/mutiny/mutants/mutant.rb', line 6

def mutation_name
  @mutation_name
end

#stillbornObject (readonly) Also known as: stillborn?

Returns the value of attribute stillborn.



6
7
8
# File 'lib/mutiny/mutants/mutant.rb', line 6

def stillborn
  @stillborn
end

#subjectObject (readonly)

Returns the value of attribute subject.



6
7
8
# File 'lib/mutiny/mutants/mutant.rb', line 6

def subject
  @subject
end

Instance Method Details

#applyObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/mutiny/mutants/mutant.rb', line 23

def apply
  # Evaluate the mutated code, overidding any existing version.
  # We evaluate in the context of TOPLEVEL_BINDING as we want
  # the unit to be evaluated in its usual namespace.
  # rubocop:disable Eval
  eval(code, TOPLEVEL_BINDING)
  # rubocop:enable Eval
rescue
  @stillborn = true
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


34
35
36
# File 'lib/mutiny/mutants/mutant.rb', line 34

def eql?(other)
  other.subject == subject && other.code == code
end

#hashObject



40
41
42
# File 'lib/mutiny/mutants/mutant.rb', line 40

def hash
  [subject, code].hash
end

#identifierObject



19
20
21
# File 'lib/mutiny/mutants/mutant.rb', line 19

def identifier
  subject.relative_path.sub(/\.rb$/, ".#{index}.rb")
end