I'm trying to create a program that will take a string and reverse it and replace it with its complimentary characters. For example, if the string ATTGCC is inputted- the method reverse_it should do the output of GGCAAT.
A is replaced by T, T is replaced by A, C is replaced by G, and G is replaced by C
This is my code:
def initialize (nucleotide)
@nucleotide = nucleotide
puts nucleotide.reverse.gsub("C", "G").gsub("G", "C").gsub("A", "T").gsub("T", "A")
dna1 = DNA.new("ATTGCC")
You are probably looking for tr, so in your method instead of
gsub, something like:
nucleotide.reverse.tr "ATCG", "TAGC"