class ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy
# => “special_request”
example.request.to_s
“special_request”
(Backtrace information…)
@request.to_s
# => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
example.old_request.to_s
# => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
example = Example.new
end
end
@request
def old_request
end
@_request
def request
end
@_request = :special_request
@request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request)
def initialize
class Example
is specified.
argument. The deprecator defaults to ActiveSupport::Deprecator
if none
and an instance variable. It optionally takes a deprecator as the last
deprecated one. It takes an instance of a class, a method on that class
DeprecatedInstanceVariableProxy transforms an instance variable into a
def initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance)
def initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance) @instance = instance @method = method @var = var @deprecator = deprecator end
def target
def target @instance.__send__(@method) end
def warn(callstack, called, args)
def warn(callstack, called, args) @deprecator.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack) end