Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Created November 8, 2011 23:57
Show Gist options
  • Save brianstorti/1349771 to your computer and use it in GitHub Desktop.
Save brianstorti/1349771 to your computer and use it in GitHub Desktop.
Ruby deprecate using dynamic methods
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