Skip to content

Instantly share code, notes, and snippets.

@ndelage
Created January 19, 2015 16:35
Show Gist options
  • Save ndelage/15fcde7f8ba8a3798c38 to your computer and use it in GitHub Desktop.
Save ndelage/15fcde7f8ba8a3798c38 to your computer and use it in GitHub Desktop.
Inheritance & Instance Variables with Ruby
class Mammal
def initialize
@fur = true
@milk = true
@eggs = false
end
def generate_lifespan
@lifespan = rand(7..92)
self
end
end
class Dog < Mammal
def initialize
@legs = 4
super
end
end
# How many instance variables? Which ones?
p Dog.new
# How many instance variables? Which ones?
p Dog.new.generate_lifespan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment