K
Kero
Hi all,
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.
Note that the 'discarding old initialize' is on line 22, not line 12.
$ ruby1.6 -v hash_include.rb
ruby 1.6.8 (2003-07-09) [i386-linux]
{}
InsertInit / II: #<Foo:0xb7fd90cc>
II: #<Foo:0xb7fd90cc>
hash_include.rb:22: warning: method redefined; discarding old initialize
hash_include.rb:23:in `initialize': superclass method `initialize' disabled
(NameError)
from hash_include.rb:26:in `new'
from hash_include.rb:26
$ ruby1.8 -v hash_include.rb
ruby 1.8.3 (2005-06-23) [i486-linux]
{}
InsertInit / II: #<Foo:0xb7fd6674>
II: #<Foo:0xb7fd6674>
hash_include.rb:22: warning: method redefined; discarding old initialize
InsertInit / {}
$ cat hash_include.rb
module InsertInit
def initialize(*args)
super()
puts "InsertInit / #{self.inspect}"
end
def inspect()
"II: #{super}"
end
end
class Hash
include InsertInit
end
p Hash.new() # {} does not call #initialize at all (only ::allocate?)
class Foo
include InsertInit
end
p Foo.new("hello")
class Hash
def initialize(*args)
super(*args)
end
end
Hash.new()
+--- Kero ------------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://members.chello.nl/k.vangelder ---+
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.
Note that the 'discarding old initialize' is on line 22, not line 12.
$ ruby1.6 -v hash_include.rb
ruby 1.6.8 (2003-07-09) [i386-linux]
{}
InsertInit / II: #<Foo:0xb7fd90cc>
II: #<Foo:0xb7fd90cc>
hash_include.rb:22: warning: method redefined; discarding old initialize
hash_include.rb:23:in `initialize': superclass method `initialize' disabled
(NameError)
from hash_include.rb:26:in `new'
from hash_include.rb:26
$ ruby1.8 -v hash_include.rb
ruby 1.8.3 (2005-06-23) [i486-linux]
{}
InsertInit / II: #<Foo:0xb7fd6674>
II: #<Foo:0xb7fd6674>
hash_include.rb:22: warning: method redefined; discarding old initialize
InsertInit / {}
$ cat hash_include.rb
module InsertInit
def initialize(*args)
super()
puts "InsertInit / #{self.inspect}"
end
def inspect()
"II: #{super}"
end
end
class Hash
include InsertInit
end
p Hash.new() # {} does not call #initialize at all (only ::allocate?)
class Foo
include InsertInit
end
p Foo.new("hello")
class Hash
def initialize(*args)
super(*args)
end
end
Hash.new()
+--- Kero ------------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://members.chello.nl/k.vangelder ---+