Skip to content

Instantly share code, notes, and snippets.

@harukizaemon
Created January 11, 2010 11:08
Show Gist options
  • Select an option

  • Save harukizaemon/274156 to your computer and use it in GitHub Desktop.

Select an option

Save harukizaemon/274156 to your computer and use it in GitHub Desktop.
Or you could use Forwardable#def_delegate
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