Created
January 11, 2010 11:08
-
-
Save harukizaemon/274156 to your computer and use it in GitHub Desktop.
Or you could use Forwardable#def_delegate
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 Sobriquet | |
| module CoreExt | |
| module Module | |
| # Use this in place of alias_method to create a _real_ alias, one that | |
| # actually calls the aliased method rather than taking a copy of it. | |
| def sobriquet(new_name, old_name) | |
| method = instance_method(old_name) | |
| arity = method.arity.abs | |
| source_location = method.source_location | |
| args = ("a".."z").take(arity) | |
| args[-1] = "*#{args[-1]}" if method.arity < 0 | |
| args = args.push("&block") | |
| args = args.join(",") | |
| definition = <<-EOE | |
| def #{new_name}(#{args}) | |
| #{old_name}(#{args}) | |
| end | |
| EOE | |
| class_eval(definition, source_location.first, source_location.last) | |
| end | |
| end | |
| end | |
| end | |
| class Module | |
| include Sobriquet::CoreExt::Module | |
| sobriquet :soubriquet, :sobriquet | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment