Created
March 16, 2012 06:32
-
-
Save nordringrayhide/2048790 to your computer and use it in GitHub Desktop.
super instead alias_method_chain
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
class A | |
def foo | |
puts 'A#foo' | |
end | |
end | |
class B < A | |
def foo | |
super | |
puts 'B#foo' | |
end | |
end | |
B.new.foo | |
=> A#foo | |
=> B#foo | |
--- #2 | |
module A | |
def foo | |
puts 'A#foo' | |
end | |
end | |
class B | |
include A | |
def foo | |
super | |
puts 'B#foo' | |
end | |
end | |
B.new.foo | |
=> A#foo | |
=> B#foo | |
-- #3 | |
module A | |
def foo | |
puts 'A#foo' | |
end | |
end | |
module B | |
def foo | |
puts 'B#foo' | |
end | |
end | |
class C | |
include B | |
include A | |
end | |
C.new.foo | |
puts "foo method owner is #{ C.new.method(:foo).owner.inspect }" | |
B#foo | |
foo method owner is B | |
-- #4 | |
module A | |
def foo | |
puts 'A#foo' | |
end | |
end | |
module B | |
def foo | |
puts 'B#foo' | |
end | |
end | |
class C | |
include B | |
include A | |
def foo | |
super | |
puts 'C#foo' | |
end | |
end | |
C.new.foo | |
=> A#foo | |
=> C#foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment