===
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 2013-03-21 15:27
on 2013-03-22 00:04
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.