Created
November 8, 2011 23:57
-
-
Save brianstorti/1349771 to your computer and use it in GitHub Desktop.
Ruby deprecate using dynamic 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
module Kernel | |
def 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 | |
end | |
class A | |
deprecate :getSomething, :get_something | |
deprecate :methodWithArgAndBlock, :method_with_arg_and_block | |
def get_something | |
"something" | |
end | |
def method_with_arg_and_block(arg1, arg2) | |
puts arg1 + arg2 | |
puts yield | |
end | |
end | |
a = A.new | |
puts a.getSomething | |
a.methodWithArgAndBlock(2, 2) do | |
"a block" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment