diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/aliasing.rb | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index e67cf940f6..45069f52af 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -3,3 +3,4 @@ require File.dirname(__FILE__) + '/module/attribute_accessors' require File.dirname(__FILE__) + '/module/delegation' require File.dirname(__FILE__) + '/module/introspection' require File.dirname(__FILE__) + '/module/loading' +require File.dirname(__FILE__) + '/module/aliasing' 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 |