在Ruby中(甚至更多:Rails),它是easy to mark methods as deprecated。如何在Ruby中將類標記爲已棄用?
但是,我怎樣才能將整個班級標記爲已棄用?我想提出只要使用一類的警告:
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
- 塊將是堅持這種警告的地方。那是正確的地方嗎?還是有更好的方法?
在你的例子中,當你剛纔定義了'const_missing'時,怎麼會被解僱呢? – berkes
@berkes第一部分不應該在那裏,錯別字 –
在'const_missing'方法中,PaymentMethod \ n end到底是什麼? – berkes