Skip to content

Instantly share code, notes, and snippets.

@gguerini
Last active December 19, 2015 01:08
Show Gist options
  • Save gguerini/5873417 to your computer and use it in GitHub Desktop.
Save gguerini/5873417 to your computer and use it in GitHub Desktop.
module ModuleTest
def foo
puts "- Foo on ModuleTest"
super # calls the Foo method on the Parent's class
end
end
class Parent
def foo
puts "- Foo on Parent's class"
end
end
class FirstChild < Parent
include ModuleTest
def foo
puts "- Foo on Child's class"
super # calls the Foo method on the Module
end
end
class SecondChild < Parent
def foo
super # calls the Foo method on the Parent's class
puts "- Foo on Second Child's class"
end
end
class ThirdChild
include ModuleTest
def foo
super # calls the Foo method on the the Module
puts "- Foo on Third Child's class"
end
end
puts "Parent:"
parent = Parent.new
parent.foo
# - Foo on Parent's class
puts "First Child:"
first_child = FirstChild.new
first_child.foo
# - Foo on Child's class
# - Foo on ModuleTest
# - Foo on Parent's class
puts "Second Child:"
second_child = SecondChild.new
second_child.foo
# - Foo on Parent's class
# - Foo on Second Child's class
puts "Third Child:"
third_child = ThirdChild.new
third_child.foo
# - Foo on ModuleTest
# foo': super: no superclass method `foo' for #<ThirdChild:0x007fd6130a64a0> (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment