I’m just wondering if the behaviour of included modules is expected to
change in Ruby 1.9.
This question has been raised from the following thread :
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/241164
As of Ruby 1.8, it seems that included modules have a behaviour
similar as class variables/methods.
module M
end
class B
include M
@@var = “Hello”
end
class C < B
end
p C.ancestors # => [C, B, M, Object, Kernel]
class C
include M
end
p C.ancestors # => [C, B, M, Object, Kernel]
The class variable @@var is shared/inherited from B.
Likewise, the module M is shared from B and is not included directly
by C.
Conversely :
module M
end
class B
end
class C < class B
include M
@@var = “Hello”
end
class B
include M
@@var = “Goodbye”
end
p C.ancestors # => [C, M, B, M, Object, Kernel]
The two class variables @@var are different.
Likewise, the module M is include both by C and by B.
Question :
As of Ruby 1.9, a class variable/method will be static to the class.
What about the included module ?
Is is planned that including a module is “static” to the class ?
Thus, if a class C include M, M is actually included by C
independently of the fact that M is included or not by a superclass of
C.
Thanks for any clarification.