Skip to content

Instantly share code, notes, and snippets.

@osheroff
Created February 10, 2012 12:12
Show Gist options
  • Save osheroff/1789180 to your computer and use it in GitHub Desktop.
Save osheroff/1789180 to your computer and use it in GitHub Desktop.
wrap up multiple metapatches
class Module
def wrap_methods(*args)
methods = args
feature = args.pop
wrapper = "_#{feature}_wrapper"
methods.each do |method|
alias_method_chain(method, feature) do |aliased_target, punctuation|
original_method = "#{aliased_target}_without_#{feature}#{punctuation}"
class_eval <<-EOL
def #{aliased_target}_with_#{feature}#{punctuation}(*args, &block)
#{wrapper}("#{original_method}", *args, &block)
end
EOL
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment