Skip to content

Instantly share code, notes, and snippets.

@jbfink
Created January 23, 2011 19:45
Show Gist options
  • Save jbfink/792365 to your computer and use it in GitHub Desktop.
Save jbfink/792365 to your computer and use it in GitHub Desktop.
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
@jbfink
Copy link
Author

jbfink commented Jan 24, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment