Skip to content

Instantly share code, notes, and snippets.

@kachick
Created May 16, 2012 04:29
Show Gist options
  • Select an option

  • Save kachick/2707404 to your computer and use it in GitHub Desktop.

Select an option

Save kachick/2707404 to your computer and use it in GitHub Desktop.
Module::Deprecatable
class Module
module Deprecatable
def deprecated(name, options={})
older = :"_deprecated_#{name}"
alias_method older, name
private older
define_method name do |*args, &block|
warn "#{__FILE__}:#{__LINE__}:WARN #{self.class}##{name} was deprecated, use new API #{self.class}##{options[:newer]}"
__send__ older, *args, &block
end
end
end
include Deprecatable
end
class My
def a
puts 'HERE'
end
deprecated :a, newer: :b
end
My.new.a #=> module-deprecatable.rb:10:WARN My#a was deprecated, use new API My#b
#=> "HERE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment