Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Ruby Inheritance
# Inheritance is an important idea for Object Orientated Programming OOP
# This example will demo a simple example of inheritance
class Dog
def talk
puts "Woof"
class JackRussell < Dog
class BichonFrise
roo =
candy =
" undefined method `talk' "
# Notice that the class JackRussell inherits from the class Dog on line 10.
# While JackRussell has no talk method defined, it inherits the talk method
# from the parent or Super class of Dog. This is why returns "Woof"
# Meanwhile returns undefined method as it is talk is not defined
# in the class BichonFrise nor did it inherit from the class Dog (line 21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment