Skip to content

Instantly share code, notes, and snippets.

@avdi
Forked from lmarburger/hack.rb
Created May 17, 2012 17:34
Show Gist options
  • Save avdi/2720428 to your computer and use it in GitHub Desktop.
Save avdi/2720428 to your computer and use it in GitHub Desktop.
Possible for a module included somewhere to override a class's instance method?
class Base
def call
'call'
end
end
Base.new.call # => "call"
module Override
def new(*)
super.extend(Pwned)
end
module Pwned
def call
"pwned! #{super.inspect}"
end
end
end
class Base
extend Override
end
Base.new.call # => "pwned! \"call\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment