Module's superclass?

===
module S1
def initialize
puts ‘s1’
end
end
module T1
def initialize
puts ‘t1’
end
end

class MyC
include S1
include T1
def initialize
puts ‘myc’
super()
end
end

MyC.new

output

myc
t1

so, I can’t call all the chain of initialize() of all included modules
in MyC ?

and

====
module S1
def initialize
puts ‘s1’
end
end
module T1
def initialize
puts ‘t1’
super()
end
end

class MyC
include S1
include T1
def initialize
puts ‘myc’
super()
end
end

MyC.new

output

myc
t1
s1

how’s that super() in T1 calls initialize() in S1 ???

On Thu, Mar 21, 2013 at 9:27 AM, Eugeni K. [email protected]
wrote:

end
MyC.new

puts 't1'

end

how’s that super() in T1 calls initialize() in S1 ???


Posted via http://www.ruby-forum.com/.

Look at MyC.ancestors:
=> [MyC, T1, S1, Object, Kernel, BasicObject]

so the super() in MyC#initialize calls T1#initialize. Then super() in
T1#initialize will call S1#initialize. If you call super() in
S1#initialize, it would call Object#initialize, and so on up the
ancestor chain.