Skip to content

Instantly share code, notes, and snippets.

@zbelzer
Created March 8, 2011 22:42
Show Gist options
  • Save zbelzer/861268 to your computer and use it in GitHub Desktop.
Save zbelzer/861268 to your computer and use it in GitHub Desktop.
# 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