Added Module#alias_method_chain
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4276 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
fe8db23371
commit
794d93f7a5
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Added Module#alias_method_chain [Jamis Buck]
|
||||
|
||||
* Updated to Builder 2.0 [DHH]
|
||||
|
||||
* Add Array#split for dividing arrays into one or more subarrays by value or block. [Sam Stephenson]
|
||||
|
@ -3,3 +3,4 @@
|
||||
require File.dirname(__FILE__) + '/module/delegation'
|
||||
require File.dirname(__FILE__) + '/module/introspection'
|
||||
require File.dirname(__FILE__) + '/module/loading'
|
||||
require File.dirname(__FILE__) + '/module/aliasing'
|
||||
|
16
activesupport/lib/active_support/core_ext/module/aliasing.rb
Normal file
16
activesupport/lib/active_support/core_ext/module/aliasing.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user