Last active
August 29, 2015 14:24
-
-
Save amicojeko/26b6848df19c277cee0b to your computer and use it in GitHub Desktop.
Broken Module Prepend 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
module ExtraMessageLogging | |
def do_something | |
super | |
puts "Prepend from #{self.class.name}" | |
end | |
end | |
module AnotherExtraMessageLogging | |
def do_something | |
super | |
puts "Prepend from #{self.class.name}" | |
end | |
end | |
class ParentClass | |
def do_something | |
puts "In parent" | |
end | |
prepend ExtraMessageLogging | |
end | |
class ChildClass < ParentClass | |
def do_something | |
puts "In child" | |
end | |
prepend ExtraMessageLogging | |
end | |
class AnotherChildClass < ParentClass | |
def do_something | |
puts "In smarter child" | |
end | |
prepend AnotherExtraMessageLogging | |
end | |
ParentClass.new.do_something | |
p '----' | |
ChildClass.new.do_something | |
p '----' | |
AnotherChildClass.new.do_something |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment