edge badge

DeprecatedConstantProxy transforms a constant into a deprecated constant. It takes the names of an old (deprecated) constant and a new contstant (both in string form), and optionally a deprecator. The deprecator defaults to ActiveSupport::Deprecator if none is specified. The deprecated constant now returns the return value of the new constant.

PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)

(In a later update, the orignal implementation of `PLANETS` has been removed.)

PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')

PLANETS.map { |planet| planet.capitalize }
# => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
     (Bactrace information…)
     ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
Methods
C
N
Class Public methods
new(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance)
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 122
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance)
  @old_const = old_const
  @new_const = new_const
  @deprecator = deprecator
end
Instance Public methods
class()
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 128
def class
  target.class
end