module A
def foo
puts 'foo from A'
super
end
end
module B
def foo
puts 'foo from B'
super
end
end
class Base
include A, B
def foo
puts 'foo from Base'
end
end
Base.new.foo
# => foo from BaseOne way to solve is to use prepend instead of include, introduced by Ruby 2.0.
Considering the compatibility, Rails may not start to use it. Here is the Rails way to solve
module A
def foo
puts 'foo from A'
super
end
end
module B
def foo
puts 'foo from B'
super
end
end
class Metal
def foo
puts 'foo from Base'
end
end
class Base
include A, B
end
Base.new.foo
# => foo from A
# => foo from B
# => foo from Base