Deprecation in Ruby
メソッド内で呼び出す
与えられる情報
終了するバージョン
ライブラリ名(デフォルトは"Rails")
与えられる情報
終了するバージョン
ライブラリ名(デフォルトは"Rails")
replacement
warning messageに使われるのみ
code:ruby
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
自前で実装する
code:ruby
class Module
def deprecate(method_name)
module_eval <<-END
alias_method :deprecated_#{method_name}, :#{method_name}
deprecated_#{method_name}(*args, &block)
end
END
end
end