aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/aliasing.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/aliasing.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/aliasing.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/aliasing.rb b/activesupport/lib/active_support/core_ext/module/aliasing.rb
new file mode 100644
index 0000000000..a80ff0f26d
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/aliasing.rb
@@ -0,0 +1,16 @@
+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)
+ alias_method "#{target}_without_#{feature}", target
+ alias_method target, "#{target}_with_#{feature}"
+ end
+end