Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Created July 13, 2009 19:12
Show Gist options
  • Save patrickberkeley/146375 to your computer and use it in GitHub Desktop.
Save patrickberkeley/146375 to your computer and use it in GitHub Desktop.
DNA search program
class Dna
# Prompt user for input.
def pick_one
puts "Enter DNA sequence. Must contain a, t, c, and g."
input = gets.chomp
process_input(input)
end
# Hash of dna sequences and values.
# If input exists in hash, return value.
# Else request input.
def process_input(input)
dna_pairs = {"atcg" => "Human", "gtca" => "Canine", "tgac" => "Feline", "ctga" => "Reptile"}
if dna_pairs.has_key?(input)
dna_pairs.each_pair do |key,value|
if key == input
puts value + " DNA sequence found."
end
end
else
pick_one
end
end
end
# Instantiate DNA object.
dna_choice = Dna.new
# Call input method on DNA object.
dna_choice.pick_one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment