Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created February 12, 2014 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phiggins/8964349 to your computer and use it in GitHub Desktop.
Save phiggins/8964349 to your computer and use it in GitHub Desktop.
> class Taco
> def self.delicious? ; true ; end
> singleton_class.send :alias_method, :yummy?, :delicious?
> end
=> #<Class:Taco>
> Taco.yummy?
=> true
@phiggins
Copy link
Author

I had to use singleton_class.send because alias_method is private. Putting the alias in a class << self block has the advantage of working in old rubies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment