Created
March 8, 2011 22:42
-
-
Save zbelzer/861268 to your computer and use it in GitHub Desktop.
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
# Something you should probably know about alias... | |
class Parent | |
def foo | |
"bar" | |
end | |
alias :also_foo :foo | |
end | |
class Child < Parent | |
def foo | |
"baz" | |
end | |
end | |
p = Parent.new | |
c = Child.new | |
p.foo # "bar" | |
p.also_foo # "bar" | |
c.foo # "baz" | |
c.also_foo # "bar" Otherwise known as "not what we were expecting" | |
# The docs make it pretty clear that it's copying the method, | |
# but the name alias makes me think that it's referencing the same method. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment