DeprecatedConstantProxy
將常數轉換為已棄用的常數。它採取舊(已棄用)常數和新常數(兩者皆為字串形式)以及一個棄用警告器的完整名稱。已棄用的常數現在傳回新常數的值。
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", ActiveSupport::Deprecation.new)
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"]
方法
- A
- C
- E
- I
- N
- P
類別公開方法
new(*args, **options, &block) 連結
new(old_const, new_const, deprecator, message: "#{old_const} 已棄用!請改用 #{new_const}。") 連結
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 128 def initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.") Kernel.require "active_support/inflector/methods" @old_const = old_const @new_const = new_const @deprecator = deprecator @message = message end
實例公開方法
append_features(base) 連結
class() 連結
傳回新常數的類別。
PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
PLANETS.class # => Array
extended(base) 連結
inspect() 連結
請勿在 inspect 上發出棄用警告,因為 test/unit 和錯誤記錄依賴它來進行診斷。