在 Ruby(甚至更多:Rails)中,很容易将方法标记为 deprecated。
但是如何将整个课程标记为已弃用?我想在使用类时发出警告:
class BillingMethod
end
BillingMethod.new #=> DEPRECATION WARNING: the class BillingMethod is deprecated. Use PaymentMethod instead.
或者当它被用于继承时:
class Sofort < BillingMethod
end
Sofort.new #=> DEPRECATION WARNING: the class BillingMethod is deprecated. Use PaymentMethod instead.
或者,在嵌套类中使用时:
class BillingMethod::Sofort < BillingMethod
end
BillingMethod::Sofort.new #=> DEPRECATION WARNING: the class BillingMethod is deprecated. Use PaymentMethod instead.
我认为class_eval
-block 将是粘贴此类警告的地方。那是正确的地方吗?还是有更好的方法?