Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created October 25, 2012 19:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/3954864 to your computer and use it in GitHub Desktop.
Save havenwood/3954864 to your computer and use it in GitHub Desktop.
Ruby Struct for Storing DNA
DNA = Struct.new(:name, :dna, :protein)
array = []
array << DNA.new('H2', 'aaactg', 'IVL')
array << DNA.new('f9', 'ccctga', 'MET')
array[0].name
#=> "H2"
array[0].dna
#=> "aaactg"
array[1].protein
#=> "MET"
array.each do |dna|
puts "Name: #{dna.name} DNA: #{dna.dna} Protein: #{dna.protein}"
end
# Name: H2 DNA: aaactg Protein: IVL
# Name: f9 DNA: ccctga Protein: MET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment