Created
September 17, 2011 22:19
-
-
Save jaredonline/1224439 to your computer and use it in GitHub Desktop.
Method deprecation helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MethodDeprecator | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def deprecate_method(method, replacement) | |
class_eval <<-DEPRECATE_METHOD_END | |
def #{method.to_s}_with_deprecation | |
puts "WARNING: Deprecated method #{self.class}##{method.to_s} called, use #{replacement} instead. Called from #{Kernel.caller[0]}" | |
#{method.to_s}_without_deprecation | |
end | |
alias_method_chain :#{method.to_s}, :deprecation | |
DEPRECATE_METHOD_END | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kernel.caller
is the whole execution stack, isn't it? So you can useKernel.caller[1]
instead to get one level up.