Created
December 28, 2012 23:54
-
-
Save kendagriff/4403257 to your computer and use it in GitHub Desktop.
Storing objects in an array, and then accessing them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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