diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-18 03:16:53 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-18 03:16:53 +0000 |
commit | 46f092097bf2e6e827a1a3c9485e326cafc0beb6 (patch) | |
tree | 715c4492eaa8465a3eaebe83694d4858973bc053 /activesupport/lib | |
parent | a38f28fff1e9e3faeeb22ac9b7c6b3cdcb7e2b29 (diff) | |
download | rails-46f092097bf2e6e827a1a3c9485e326cafc0beb6.tar.gz rails-46f092097bf2e6e827a1a3c9485e326cafc0beb6.tar.bz2 rails-46f092097bf2e6e827a1a3c9485e326cafc0beb6.zip |
alias_method_chain preserves the original method's visibility. Closes #7854.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6441 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/aliasing.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/aliasing.rb b/activesupport/lib/active_support/core_ext/module/aliasing.rb index 81e81696d8..b36874520b 100644 --- a/activesupport/lib/active_support/core_ext/module/aliasing.rb +++ b/activesupport/lib/active_support/core_ext/module/aliasing.rb @@ -25,8 +25,20 @@ class Module # e.g. target?_without_feature is not a valid method name. aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 yield(aliased_target, punctuation) if block_given? - alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target - alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}" + + with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}" + + alias_method without_method, target + alias_method target, with_method + + case + when public_method_defined?(without_method) + public target + when protected_method_defined?(without_method) + protected target + when private_method_defined?(without_method) + private target + end end # Allows you to make aliases for attributes, which includes |