class DeprecatedInstanceVariableProxy

Ruby on Rails edge

Since v4.0.13

Available in: v4.0.13 v4.1.16 v4.2.11.3 v5.0.7.2 v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.4 v8.0.5.1 v8.1.4 edge

DeprecatedInstanceVariableProxy transforms an instance variable into a deprecated one. It takes an instance of a class, a method on that class, an instance variable, and a deprecator as a keyword argument.

Trying to use the deprecated instance variable will result in a deprecation warning, pointing to the method as a replacement.

class Example
  def initialize
    @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator: ActiveSupport::Deprecation.new)
    @_request = :special_request
  end

  def request
    @_request
  end

  def old_request
    @request
  end
end

example = Example.new
# => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>

example.old_request.to_s
# => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
   @request.to_s
   (Backtrace information…)
   "special_request"

example.request.to_s
# => "special_request"

Inherits from

ActiveSupport::Deprecation::DeprecationProxy

Methods (defined here)

Private methods (2)

Show private methods Implementation detail — not part of the public API.

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close