Created
August 24, 2011 19:32
-
-
Save h3h/1168967 to your computer and use it in GitHub Desktop.
Ruby's `alias_method` Behavior
This file contains 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
>> class Foo | |
> def bar; 1 end | |
> alias_method :baz, :bar | |
> end | |
=> Foo | |
>> class FooTwo < Foo | |
> def bar; 2 end | |
> end | |
=> nil | |
>> FooTwo.new.bar | |
=> 2 | |
>> FooTwo.new.baz | |
=> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've used this before, and found it very convenient - it does exactly what you'd expect: