From: Lazaridis Ilias Date: 2011-06-17T04:00:31+09:00 Subject: [ruby-core:37180] [Ruby 1.9 - Bug #4893] Literal Instantiation breaks Object Model Issue #4893 has been updated by Lazaridis Ilias. Konstantin Haase wrote: > On Jun 16, 2011, at 18:42 , Lazaridis Ilias wrote: > > You should reread the description, experiment a little, and take some time to respond. > > To rephrase what Magnus said: > Where does the object passed to initialize come from? How has that object been initialized? "How has that 'uninitialized object' been allocated?" would be the question. String#allocate (either called directly or via String#new) http://www.ruby-doc.org/core/classes/Class.html#M000178 Those are basics. The issue is, that after the allocation, the *redefined* initialized should be called. - There is a public topic available, with some elaborations: CORE - Literal Instantiation breaks Object Model http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/fd00b89dc6d3a7fa# http://www.ruby-forum.com/topic/1893190#new ---------------------------------------- Bug #4893: Literal Instantiation breaks Object Model http://redmine.ruby-lang.org/issues/4893 Author: Lazaridis Ilias Status: Feedback Priority: Normal Assignee: Category: Target version: ruby -v: 1.9.2 #String2.rb class String def initialize(val) self.replace(val) puts object_id end def my_method_test 'has method ' end end # command line $ irb irb(main):001:0> original = String.new("original") => "original" irb(main):002:0> load "String2.rb" => true irb(main):003:0> altered = String.new("altered") 21878604 => "altered" irb(main):004:0> altered.my_method_test => "has method " irb(main):005:0> literal = "literal" => "literal" irb(main):006:0> literal.my_method_test => "has method " irb(main):007:0> - The initialize method is an integral part of the class String. From the moment that "String2.rb" is loaded, the initialize method of class String has been validly redefined. (The behaviour of the String class within the "irb session" is altered) The altered initialize method is now an integral part of the class String. The altered String object behaves as expected (responds to "my_method_test, initialized via redefined initialize method). The String(Literal) object responds to "my_method_test", but it is was not initialized with the redefined initialize method. - The "Literal Instantiation" calls the original (core-C-level) String initialize method instead of the redefined one (user-language-level). This *breaks* the object model. -- http://redmine.ruby-lang.org