Created
January 23, 2011 19:45
-
-
Save jbfink/792365 to your computer and use it in GitHub Desktop.
This file contains 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 Dog | |
attr_accessor :ears, :legs, :nose, :smell, :name, :number | |
@@number = 0 | |
@@names = [] | |
@@dogs = [] | |
def initialize(name) | |
@ears = 2 | |
@legs = 4 | |
@nose = 1 | |
@smell = "Stinky" | |
@name = name | |
@@number +=1 | |
@number = @@number | |
@@names.push(name) | |
@@dogs.push([name, ears, legs, nose, smell, number]) | |
#works on initial object create but not when you update objects. Will have to fix. | |
#maybe by using a hash? Probably have to Actually Write Methods rather than relying on attr_accessor | |
end | |
def self.count | |
@@number | |
end | |
def self.names | |
@@names | |
end | |
def self.dogs | |
@@dogs | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ended up not being able to magically gank the name of each instance of class Dog, so I did the lazy/correct thing and made passing an explicit name string to initialize mandatory.