Module: LinkParser::DeprecationUtilities
- Included in:
- Linkage
- Defined in:
- lib/linkparser/mixins.rb
Overview
Functions for marking methods as deprecated.
Instance Method Summary collapse
-
#deprecated_method(*names) ⇒ Object
Make a wrapper for a deprecated method.
Instance Method Details
#deprecated_method(*names) ⇒ Object
Make a wrapper for a deprecated method. The wrapper will print a deprecation warning to STDERR, and then call the method with the same name prefixed with an underscore.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/linkparser/mixins.rb', line 15 def deprecated_method( *names ) names.each do |name| method_body = lambda do |*args| source = caller( 1 ).first if $lp_deprecation_warnings.key?( source ) $lp_deprecation_warnings[ source ] += 1 else $lp_deprecation_warnings[ source ] = 1 warn "Use of deprecated method %p from %s." % [ name, source ] end return self.method( "_#{name}" ).call( *args ) end # Install the wrapper after aliasing away the old method alias_method( "_#{name}", name ) remove_method( name ) define_method( name, &method_body ) end end |