From 46f092097bf2e6e827a1a3c9485e326cafc0beb6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 18 Mar 2007 03:16:53 +0000 Subject: 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 --- .../lib/active_support/core_ext/module/aliasing.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3