Yukihiro Matsumoto
7/16/2005 3:16:00 PM
Hi,
In message "Re: Bug? Hash::include not working properly"
on Sat, 16 Jul 2005 20:00:53 +0900, Kero <kero@chello.single-dot.nl> writes:
|The behaviour of both ruby 1.6 and 1.8 seems broken.
|Foo nicely overrides #initialize and #inspect when the module is
|included, but Hash does not. Feels like premature optimization to me...
|
|1.8 at least behaves properly when overriding Hash#initialize once more.
You are assuming Hash#initialize calls super in it, but it doesn't.
It's not guaranteed that initialize defined in included modules to be
called.
|class Foo
| include InsertInit
|end
|p Foo.new("hello")
Foo does not have its own implementation of initialize, whereas Hash
does. Try
class Foo
def initialize(*args)
end
include InsertInit
end
p Foo.new("hello")
to understand the situation. Note that the priority of methods
defined in the included modules are lower than methods defined in
the target class.
matz.