DeprecatedConstantProxy 将一个常量转换为一个已弃用的常量。它接受一个旧的(已弃用的)常量和一个新的常量(都以字符串形式表示)的完整名称以及一个 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", 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) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 121 def self.new(*args, **options, &block) object = args.first return object unless object super end
new(old_const, new_const, deprecator, message: "#{old_const} 已弃用!请使用 #{new_const} 代替。") 链接
来源: 显示 | 在 GitHub 上
# 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) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 158 def append_features(base) @deprecator.warn(@message, caller_locations) base.include(target) end
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
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 154 def class target.class end
extended(base) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 168 def extended(base) @deprecator.warn(@message, caller_locations) base.extend(target) end
inspect() 链接
由于 test/unit 和错误日志依赖 inspect 进行诊断,因此在 inspect 时不要发出弃用警告。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 141 def inspect target.inspect end
prepend_features(base) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation/proxy_wrappers.rb, line 163 def prepend_features(base) @deprecator.warn(@message, caller_locations) base.prepend(target) end