Created
September 18, 2013 10:09
-
-
Save ngpestelos/6607116 to your computer and use it in GitHub Desktop.
deprecate methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see Metaprogramming Ruby, p. 104 | |
class Book | |
def title | |
"title" | |
end | |
def subtitle | |
"subtitle" | |
end | |
def self.deprecate(old_method, new_method) | |
define_method(old_method) do |*args, &block| | |
warn "Warning: #{old_method}() is deprecated Use #{new_method}()." | |
send(new_method, *args, &block) | |
end | |
end | |
deprecate :GetTitle, :title | |
deprecate :LEND_TO_USER, :lend_to | |
deprecate :title2, :subtitle | |
end | |
obj = Book.new | |
puts obj.GetTitle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment