Class: Mutiny::Mutants::Mutant
- Inherits:
-
Object
- Object
- Mutiny::Mutants::Mutant
- Defined in:
- lib/mutiny/mutants/mutant.rb,
lib/mutiny/mutants/mutant/location.rb
Defined Under Namespace
Classes: Location
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#index ⇒ Object
Returns the value of attribute index.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#mutation_name ⇒ Object
readonly
Returns the value of attribute mutation_name.
-
#stillborn ⇒ Object
(also: #stillborn?)
readonly
Returns the value of attribute stillborn.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #apply ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
- #identifier ⇒ Object
-
#initialize(subject: nil, code:, mutation_name: nil, index: nil, position: nil) ⇒ Mutant
constructor
A new instance of Mutant.
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/mutiny/mutants/mutant.rb', line 6 def code @code end |
#index ⇒ Object
Returns the value of attribute index.
7 8 9 |
# File 'lib/mutiny/mutants/mutant.rb', line 7 def index @index end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/mutiny/mutants/mutant.rb', line 6 def location @location end |
#mutation_name ⇒ Object (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 |
#stillborn ⇒ Object (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 |
#subject ⇒ Object (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
#apply ⇒ Object
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: ==
34 35 36 |
# File 'lib/mutiny/mutants/mutant.rb', line 34 def eql?(other) other.subject == subject && other.code == code end |
#hash ⇒ Object
40 41 42 |
# File 'lib/mutiny/mutants/mutant.rb', line 40 def hash [subject, code].hash end |
#identifier ⇒ Object
19 20 21 |
# File 'lib/mutiny/mutants/mutant.rb', line 19 def identifier subject.relative_path.sub(/\.rb$/, ".#{index}.rb") end |