Skip to content

Instantly share code, notes, and snippets.

@fronx
Created June 30, 2009 13:28
Show Gist options
  • Save fronx/138155 to your computer and use it in GitHub Desktop.
Save fronx/138155 to your computer and use it in GitHub Desktop.
how to overwrite mixed-in methods while still having access to the original implementation via super
module X
def x
"x"
end
module_function :x
def self.included(base)
base.class_eval do
public :x
end
end
end
class TestDefault
include X
end
puts TestDefault.new.x
# => x
module OverwriteX
include X
def x
"#{super}2"
end
end
class TestOverwrite
include OverwriteX
end
puts TestOverwrite.new.x
# => x
module DontOverwriteX
include X
end
class TestDontOverwrite
include DontOverwriteX
end
puts TestDontOverwrite.new.x
# => x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment