Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 15b022a74f
Fetching contributors…

Cannot retrieve contributors at this time

20 lines (19 sloc) 0.622 kb
class Module
# Encapsulates the common pattern of:
#
# alias_method :foo_without_feature, :foo
# alias_method :foo, :foo_with_feature
#
# With this, you simply do:
#
# alias_method_chain :foo, :feature
#
# And both aliases are set up for you.
def alias_method_chain(target, feature)
# Strip out punctuation on predicates or bang methods since
# e.g. target?_without_feature is not a valid method name.
aliased_target = target.to_s.sub(/[?!]/, '')
alias_method "#{aliased_target}_without_#{feature}", target
alias_method target, "#{aliased_target}_with_#{feature}"
end
end
Jump to Line
Something went wrong with that request. Please try again.