Type:
Class

This DeprecatedInstanceVariableProxy transforms instance variable to deprecated instance variable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Example
  def initialize(deprecator)
    @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
    @_request = :a_request
  end
 
  def request
    @_request
  end
 
  def old_request
    @request
  end
end

When someone execute any method on @request variable this will trigger warn method on deprecator_instance and will fetch @_request variable via request method and execute the same method on non-proxy instance variable.

Default deprecator is ActiveSupport::Deprecation.

new
  • References/Ruby on Rails/Rails/Classes/ActiveSupport/ActiveSupport::Deprecation/ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy

new(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance) Class Public methods

2025-01-10 15:47:30