Module: Tins::Deprecate

Included in:
Array, Module, CountBy, DeepConstGet, UniqBy
Defined in:
lib/tins/deprecate.rb

Instance Method Summary collapse

Instance Method Details

#deprecate(method:, new_method: nil, message: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/tins/deprecate.rb', line 3

def deprecate(method:, new_method: nil, message: nil)
  message ||= '[DEPRECATION] `%{method}` is deprecated. Please use `%{new_method}` instead.'
  message = message % { method: method, new_method: new_method }
  m = Module.new do
    define_method(method) do |*a, **kw, &b|
      warn message
      super(*a, **kw, &b)
    end
  end
  prepend m
end