Skip to content

Instantly share code, notes, and snippets.

@nordringrayhide
Created August 10, 2012 07:51
Show Gist options
  • Save nordringrayhide/3312468 to your computer and use it in GitHub Desktop.
Save nordringrayhide/3312468 to your computer and use it in GitHub Desktop.
Ruby Multiple inheritance
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
@nordringrayhide
Copy link
Author

class C
def foo
# B#foo How ?
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment