Skip to content

Instantly share code, notes, and snippets.

@kendagriff
Created December 28, 2012 23:54
Show Gist options
  • Save kendagriff/4403257 to your computer and use it in GitHub Desktop.
Save kendagriff/4403257 to your computer and use it in GitHub Desktop.
Storing objects in an array, and then accessing them.
class IceCream
attr_reader :name
def initialize(name)
@name = name
end
end
vanilla = IceCream.new('Vanilla Ice Cream')
chocolate = IceCream.new('Chocolate Ice Cream')
ice_creams = []
ice_creams << vanilla
ice_creams << chocolate
ice_creams.each do |i|
puts i.name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment