Skip to content

Instantly share code, notes, and snippets.

@BWoodfork
Created September 1, 2015 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BWoodfork/11062668418c432935a5 to your computer and use it in GitHub Desktop.
Save BWoodfork/11062668418c432935a5 to your computer and use it in GitHub Desktop.
Polymorphism using inheritance in Ruby
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