Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Created September 18, 2013 10:09
Show Gist options
  • Save ngpestelos/6607116 to your computer and use it in GitHub Desktop.
Save ngpestelos/6607116 to your computer and use it in GitHub Desktop.
deprecate methods
# 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