class C < java.util.ArrayList
def initialize
puts "c"
super
end
end
C.new
# =>
# c
module M
def initialize
puts "m"
super
end
end
C.prepend(M)
C.new
# =>
# I would expect
# =>
# m
# c
Interestingly, if I insert an intermediate class, one of the initialize methods get called:
class C < java.util.ArrayList
def initialize
puts "c"
super
end
end
C.new
# =>
# c
class D < C
def initialize
puts "d"
super
end
end
D.new
# =>
# d
# c
module M
def initialize
puts "m"
super
end
end
D.prepend(M)
D.new
# =>
# c
# I would expect
# =>
# m
# d
# c
In general, the module and the leaf class's initializer are not called if I take it to the next level:
class C < java.util.ArrayList
def initialize
puts "c"
super
end
end
C.new
# =>
# c
class D < C
def initialize
puts "d"
super
end
end
D.new
# =>
# d
# c
class E < D
def initialize
puts "e"
super
end
end
E.new
# =>
# e
# d
# c
module M
def initialize
puts "m"
super
end
end
E.prepend(M)
E.new
# =>
# d
# c
# I would expect
# =>
# m
# e
# d
# c
If the first base class is not a Java class, all works as expected:
class C
def initialize
puts "c"
end
end
C.new
# =>
# c
class D < C
def initialize
puts "d"
super
end
end
D.new
# =>
# d
# c
module M
def initialize
puts "m"
super
end
end
D.prepend(M)
D.new
# =>
# m
# d
# c
JRuby version: jruby 10.0.4.0 (3.4.5) 2026-03-03 9af05b916f OpenJDK 64-Bit Server VM 21.0.10+7-Ubuntu-124.04 on 21.0.10+7-Ubuntu-124.04 +indy +jit [x86_64-linux]
Interestingly, if I insert an intermediate class, one of the initialize methods get called:
In general, the module and the leaf class's initializer are not called if I take it to the next level:
If the first base class is not a Java class, all works as expected:
JRuby version:
jruby 10.0.4.0 (3.4.5) 2026-03-03 9af05b916f OpenJDK 64-Bit Server VM 21.0.10+7-Ubuntu-124.04 on 21.0.10+7-Ubuntu-124.04 +indy +jit [x86_64-linux]