根据 Ruby on Rails API 文档,您可以在方法 #deprecate 的帮助下弃用方法.这一切都很好。
我的问题是;是否可以弃用静态方法 - 如果可以,如何弃用?
对于常规方法,您可以执行如下操作:
deprecate :my_method
def my_method
# ...
end
这个机器人让我头疼(而且它不工作):
deprecate :"self.my_method"
def self.my_method
# ...
end
P.s.: 我知道我可以通过这样的方法发出警告:
def self.my_method
ActiveSupport::Deprecation.warn "the warning..."
# ...
end
最佳答案
您应该在元类上调用 deprecate:
class Test1
def self.hello
puts "Test1"
end
singleton_class.deprecate :hello
# or
class << self ; deprecate :hello ; end
end
关于ruby-on-rails - 如何弃用 Rails 中的静态方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133942/