Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save slyphon/2582095 to your computer and use it in GitHub Desktop.
Save slyphon/2582095 to your computer and use it in GitHub Desktop.
class Module
# Use this to replace a method in an alias_method_chain
def inject_alias_method_chain(target, method_to_replace, method_to_use)
method_instance_to_replace = instance_method(method_to_replace)
meths = (private_instance_methods | instance_methods).sort.grep(/^#{target}/)
found = meths.detect do |m|
m != method_to_replace.to_s && instance_method(m) == method_instance_to_replace
end
if found
alias_method found, method_to_use
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment