Skip to content

Instantly share code, notes, and snippets.

@amicojeko
Last active August 29, 2015 14:24
Show Gist options
  • Save amicojeko/26b6848df19c277cee0b to your computer and use it in GitHub Desktop.
Save amicojeko/26b6848df19c277cee0b to your computer and use it in GitHub Desktop.
Broken Module Prepend in Ruby
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