Just a short test to find out what Ruby does when mixing in 2 modules which both have a method with the same name:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module ModuleA
  def testbla
     puts "Method defined in Module A"
  end
end

module ModuleB
  def testbla
    puts "Method defined in Module B"
  end
end

class TestclassAfirst
include ModuleA
include ModuleB
end

class TestclassBfirst
include ModuleB
include ModuleA
end

puts "------------"
test1 = TestclassAfirst.new
puts "First importing A and then B:"
test1.testbla
puts "------------"
test2 = TestclassBfirst.new
puts "First importing B and then A:"
test2.testbla
puts "------------"

Result:

1
2
3
4
5
First importing A and then B:
Method defined in Module B

First importing B and then A:
Method defined in Module A

Comments