Forum: Ruby Module's superclass?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9d8fd118fbbda12178880ff5d353b785?d=identicon&s=25 Eugeni Kurtov (lessless)
on 2013-03-21 15:27
===
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 ???
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse mailing lists (Guest)
on 2013-03-22 00:04
(Received via mailing list)
On Thu, Mar 21, 2013 at 9:27 AM, Eugeni Kurtov <lists@ruby-forum.com>
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.
This topic is locked and can not be replied to.