Skip to content

Instantly share code, notes, and snippets.

@aprescott
Created February 13, 2014 20:03
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 aprescott/8982740 to your computer and use it in GitHub Desktop.
Save aprescott/8982740 to your computer and use it in GitHub Desktop.
# 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