Created
May 16, 2012 04:29
-
-
Save kachick/2707404 to your computer and use it in GitHub Desktop.
Module::Deprecatable
This file contains hidden or 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
| 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