Created
October 22, 2014 11:50
-
-
Save jheg/959bba09235c2a8e104d to your computer and use it in GitHub Desktop.
inheritance
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 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