Skip to content

Commit

Permalink
Fix deprecating =-methods by using send [#2431 status:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
siebertm authored and lifo committed Aug 9, 2009
1 parent 2d2216f commit 4c96030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 9 additions & 9 deletions activesupport/lib/active_support/deprecation.rb
Expand Up @@ -90,15 +90,15 @@ def deprecate(*method_names)
method_names.each do |method_name|
alias_method_chain(method_name, :deprecation) do |target, punctuation|
class_eval(<<-EOS, __FILE__, __LINE__)
def #{target}_with_deprecation#{punctuation}(*args, &block) # def generate_secret_with_deprecation(*args, &block)
::ActiveSupport::Deprecation.warn( # ::ActiveSupport::Deprecation.warn(
self.class.deprecated_method_warning( # self.class.deprecated_method_warning(
:#{method_name}, # :generate_secret,
#{options[method_name].inspect}), # "You should use ActiveSupport::SecureRandom.hex(64)"),
caller # caller
) # )
#{target}_without_deprecation#{punctuation}(*args, &block) # generate_secret_without_deprecation(*args, &block)
end # end
def #{target}_with_deprecation#{punctuation}(*args, &block) # def generate_secret_with_deprecation(*args, &block)
::ActiveSupport::Deprecation.warn( # ::ActiveSupport::Deprecation.warn(
self.class.deprecated_method_warning( # self.class.deprecated_method_warning(
:#{method_name}, # :generate_secret,
#{options[method_name].inspect}), # "You should use ActiveSupport::SecureRandom.hex(64)"),
caller # caller
) # )
send(:#{target}_without_deprecation#{punctuation}, *args, &block) # send(:generate_secret_without_deprecation, *args, &block)
end # end
EOS
end
end
Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/deprecation_test.rb
Expand Up @@ -25,6 +25,9 @@ def d; end
def e; end
deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one"

def f=(v); end
deprecate :f=

module B
C = 1
end
Expand Down Expand Up @@ -133,6 +136,7 @@ def test_silence
def test_deprecation_without_explanation
assert_deprecated { @dtc.a }
assert_deprecated { @dtc.b }
assert_deprecated { @dtc.f = :foo }
end

def test_deprecation_with_alternate_method
Expand Down

0 comments on commit 4c96030

Please sign in to comment.