Skip to content

Instantly share code, notes, and snippets.

@jheg
Created October 22, 2014 11:50
Show Gist options
  • Save jheg/959bba09235c2a8e104d to your computer and use it in GitHub Desktop.
Save jheg/959bba09235c2a8e104d to your computer and use it in GitHub Desktop.
inheritance
class Animal
def speak
"Hello!"
end
end
class GoodDog < Animal
attr_accessor :name
def initialize(n)
self.name = n
end
def speak
"#{self.name} says arf!"
end
end
class Cat < Animal
end
sparky = GoodDog.new("Sparky")
paws = Cat.new
puts sparky.speak # => Sparky says arf!
puts paws.speak # => Hello!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment