Created
February 13, 2014 20:03
-
-
Save aprescott/8982740 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Demonstration showing that | |
# | |
# alias_method :bar, :foo | |
# | |
# is not equivalent to | |
# | |
# def bar | |
# foo | |
# end | |
class Entity | |
def foo | |
p :entity_foo | |
end | |
end | |
class Thing < Entity | |
alias_method :bar, :foo | |
end | |
class Person < Thing | |
def foo | |
p :person_foo | |
super | |
end | |
def bar | |
p :person_bar | |
super | |
end | |
end | |
Person.new.bar | |
# :person_bar | |
# :entity_foo | |
# ----------------------------------- | |
class Entity | |
def foo | |
p :entity_foo | |
end | |
end | |
class Thing < Entity | |
def bar | |
p method(:foo) | |
foo | |
end | |
end | |
class Person < Thing | |
def foo | |
p :person_foo | |
super | |
end | |
def bar | |
p :person_bar | |
super | |
end | |
end | |
Person.new.bar | |
# :person_bar | |
# #<Method: Person#foo> | |
# :person_foo | |
# :entity_foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment