非推奨なメソッドに警告をだす

 1 class Module
 2   def deprecate(method_name, &block)
 3     module_eval <<-END
 4       alias_method :deprecated_#{method_name}, :#{method_name}
 5       def #{method_name}(*args, &block)
 6         $stderr.puts "Warning: calling deprecated method #{self}.#{method_name}"
 7         deprecated_#{method_name}(*args, &block)
 8       end
 9     END
10   end
11 end
12 
13 class Foo
14   def foo
15     puts "deprecated"
16   end
17 
18   deprecate :foo
19 end



comments powered by Disqus


© 2015 kyuden