класс ActiveSupport::Deprecation::DeprecatedConstantProxy
DeprecatedConstantProxy преобразует константу в устаревшую. Она принимает имена старой (устаревшей) константы и новой константы (оба в строковом формате) и необязательно объект deprecator. Если deprecator не указан, используется значение по умолчанию ActiveSupport::Deprecator. Устаревшая константа теперь возвращает значение новой.
PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
(In a later update, the original 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.
(Backtrace information…)
["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] Публичные методы класса
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 124 def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance) @old_const = old_const @new_const = new_const @deprecator = deprecator end
Публичные методы экземпляра
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 135 def class target.class end
Возвращает класс новой константы.
PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
PLANETS.class # => Array
© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.