本文簡要介紹ruby語言中 Gem::Deprecate模塊
的用法。
提供 3 種方法來聲明某事何時消失。
+棄用(名稱,repl,年,月)+:
Indicate something may be removed on/after a certain date.
+rubygems_deprecate(名稱,替換=:無)+:
Indicate something will be removed in the next major RubyGems version, and (optionally) a replacement for it.
rubygems_deprecate_command
:
Indicate a RubyGems command (in +lib/rubygems/commands/*.rb+) will be removed in the next RubyGems version.
還提供 skip_during
用於暫時關閉棄用警告。這旨在用於測試套件,因此如果您需要確保 stderr 為空,則棄用警告不會導致測試失敗。
deprecate
和 rubygems_deprecate
的示例用法:
class Legacy
def self.some_class_method
# ...
end
def some_instance_method
# ...
end
def some_old_method
# ...
end
extend Gem::Deprecate
deprecate :some_instance_method, "X.z", 2011, 4
rubygems_deprecate :some_old_method, "Modern#some_new_method"
class << self
extend Gem::Deprecate
deprecate :some_class_method, :none, 2011, 4
end
end
rubygems_deprecate_command
的示例用法:
class Gem::Commands::QueryCommand < Gem::Command
extend Gem::Deprecate
rubygems_deprecate_command
# ...
end
skip_during
的示例用法:
class TestSomething < Gem::Testcase
def test_some_thing_with_deprecations
Gem::Deprecate.skip_during do
actual_stdout, actual_stderr = capture_output do
Gem.something_deprecated
end
assert_empty actual_stdout
assert_equal(expected, actual_stderr)
end
end
end
相關用法
- Ruby DependencyState.pop_possibility_state用法及代碼示例
- Ruby DependencyGraph.==用法及代碼示例
- Ruby DependencyGraph.vertices用法及代碼示例
- Ruby DependencyGraph.tsort用法及代碼示例
- Ruby Deflate.new用法及代碼示例
- Ruby Delegator類用法及代碼示例
- Ruby Deflate.deflate用法及代碼示例
- Ruby DefMethod模塊用法及代碼示例
- Ruby Date.valid_civil?用法及代碼示例
- Ruby DateTime jisx0301()用法及代碼示例
- Ruby Date cwday()用法及代碼示例
- Ruby Date ctime()用法及代碼示例
- Ruby Date.gregorian?用法及代碼示例
- Ruby DRb.regist_server用法及代碼示例
- Ruby DH.public_key用法及代碼示例
- Ruby Date asctime()用法及代碼示例
- Ruby DateTime類用法及代碼示例
- Ruby DateTime.hour用法及代碼示例
- Ruby DateTime.jd用法及代碼示例
- Ruby DateTime.zone用法及代碼示例
- Ruby DateTime ordinal()用法及代碼示例
- Ruby DateTime.second用法及代碼示例
- Ruby Date.strftime用法及代碼示例
- Ruby Digest.update用法及代碼示例
- Ruby DSA.export用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Deprecate模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。