Changeset 5113
- Timestamp:
- 09/15/06 03:42:54 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/module/aliasing.rb
r5091 r5113 25 25 # e.g. target?_without_feature is not a valid method name. 26 26 aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 27 yield(aliased_target, punctuation) if block_given? 27 28 alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target 28 29 alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}" trunk/activesupport/lib/active_support/deprecation.rb
r4982 r5113 73 73 def deprecate(*method_names) 74 74 method_names.each do |method_name| 75 class_eval(<<-EOS, __FILE__, __LINE__) 76 def #{method_name}_with_deprecation(*args, &block) 77 ::ActiveSupport::Deprecation.warn("#{method_name} is deprecated and will be removed from Rails 2.0", caller) 78 #{method_name}_without_deprecation(*args, &block) 79 end 80 EOS 81 alias_method_chain(method_name, :deprecation) 75 alias_method_chain(method_name, :deprecation) do |target, punctuation| 76 class_eval(<<-EOS, __FILE__, __LINE__) 77 def #{target}_with_deprecation#{punctuation}(*args, &block) 78 ::ActiveSupport::Deprecation.warn("#{method_name} is deprecated and will be removed from Rails 2.0", caller) 79 #{target}_without_deprecation#{punctuation}(*args, &block) 80 end 81 EOS 82 end 82 83 end 83 84 end trunk/activesupport/test/core_ext/module_test.rb
r5091 r5113 101 101 module BarMethodAliaser 102 102 def self.included(foo_class) 103 foo_class.send :include, BarMethods 103 104 foo_class.alias_method_chain :bar, :baz 104 105 end 105 106 end 107 108 module BarMethods 106 109 def bar_with_baz 107 110 bar_without_baz << '_with_baz' … … 204 207 end 205 208 end 206 end 209 210 def test_alias_method_chain_yields_target_and_punctuation 211 FooClassWithBarMethod.send(:define_method, :quux?, Proc.new { }) 212 FooClassWithBarMethod.send :include, BarMethods 213 block_called = false 214 FooClassWithBarMethod.alias_method_chain :quux?, :baz do |target, punctuation| 215 block_called = true 216 assert_equal 'quux', target 217 assert_equal '?', punctuation 218 end 219 assert block_called 220 end 221 end