Created
August 10, 2012 07:51
-
-
Save nordringrayhide/3312468 to your computer and use it in GitHub Desktop.
Ruby Multiple inheritance
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
module A | |
def foo | |
'A#foo' | |
end | |
end | |
module B | |
def foo | |
'B#foo' | |
end | |
end | |
class C | |
include A | |
include B | |
end | |
puts C.new.foo | |
# B#foo | |
Object.send :remove_const, :C | |
class C | |
include B | |
include A | |
end | |
puts C.new.foo | |
A#foo | |
puts "C.new.foo owner => #{ C.new.method(:foo).owner }" | |
# C.new.foo owner => A | |
class C | |
def foo; end | |
end | |
puts "C.new.foo owner => #{ C.new.method(:foo).owner }" | |
# C.new.foo owner => C | |
class C | |
def foo | |
# B#foo or A#foo # How to resolve method call collision? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class C
def foo
# B#foo How ?
end
end