Created
September 1, 2015 00:01
-
-
Save BWoodfork/11062668418c432935a5 to your computer and use it in GitHub Desktop.
Polymorphism using inheritance in Ruby
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 sleep | |
puts "#{self.class} is sleeping." | |
end | |
end | |
class Frog < Animal | |
def make_noise | |
"Ribbet Ribbet" | |
end | |
def move | |
puts "#{self.class} is hopping." | |
end | |
end | |
class Dog < Animal | |
def make_noise | |
"Woof Woof" | |
end | |
def move | |
puts "#{self.class} is running." | |
end | |
end | |
class Fish < Animal | |
def make_noise | |
"Guppy Gruppy" | |
end | |
def move | |
puts "#{self.class} is swimming." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment