There is a class called DNA. a variable called nucleotide gets initialized. In the class the length of the nucleotide is found, two different nucleotides are checked to see if they are equal, and the hamming distance is displayed. '
My problem is Ruby only interprets one instance of nucleotide. How do I compare nucleotide to other nucleotides that get created?
def initialize (nucleotide)
@nucleotide = nucleotide
puts @nucleotide == @nucleotide
dna1 = DNA.new("ATTGCC")
dna2 = DNA.new("GTTGAC")
dna1 = DNA.new('ATTGCC')
>> dna2 = DNA.new('GTTGAC')
You need to make nucleotide an accessible field. In this example, I've made it protected, but you could make it public.
class DNA def initialize(nucleotide) @nucleotide = nucleotide end def length @nucleotide.length end def hamming_distance(other) self.nucleotide #=> this nucleotide other.nucleotide #=> incoming nucleotide end protected attr_reader :nucleotide end
Then use it like:
one = DNA.new("ATTGCC") two = DNA.new("GTTGAC") one.hamming_distance(two)