Skip to content

Instantly share code, notes, and snippets.

@jaredonline
Created September 17, 2011 22:19
Show Gist options
  • Save jaredonline/1224439 to your computer and use it in GitHub Desktop.
Save jaredonline/1224439 to your computer and use it in GitHub Desktop.
Method deprecation helper
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
@Umofomia
Copy link

Kernel.caller is the whole execution stack, isn't it? So you can use Kernel.caller[1] instead to get one level up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment