From: Lazaridis Ilias Date: 2011-06-18T01:12:52+09:00 Subject: [ruby-core:37203] [Ruby 1.9 - Bug #4893] Literal Instantiation breaks Object Model Issue #4893 has been updated by Lazaridis Ilias. Yukihiro Matsumoto wrote: > Your request has been too vague for me. > Your definition of terms such as "object model" seems different from others. I don't think so: "Object Model" as in * Design and implementation of a programming language's OO behaviour (classes, object, inheritance, mixin, methods, attributes, per-instance-behaviour etc.). Special part of this language's (ruby) "Object Model" is * Primitive data types (integer, string, ...) are objects, and have related classes (Integer, String) * Classes (including those of the primitive data types) can be redefined at runtime. This is a flexible ability, but it has (in the current implementation) a limitation (essentially a bug): * Limitation: a redefined initialize method is *not* called during "literal instantiation" > Probably the code will tell what you want. Mr. Matsumoto. Will you honestly insist that you have not understood (after the public thread, and the compact irb demonstration) that "what I want" is: * The *redefined* initialize method *must* be called during literal instantiation (when instantiating objects from literals)? > I will reopen this issue when a patch is posted This means that this issue is on "Standby" or "Feedback" and not "Rejected". I think you abuse your position here, because you take the freedom to process this issue based on your personal feelings or bias, instead of the existent facts. You should respect my time more (I've already invested more that a week with this issue on a OO user-level, and I need some confirmations prior to continuing on C-core-level. I have to use the official ruby interpreter, thus it makes no sense for me to invest time for a patch which has no chance to be applied. (Btw: This modification/patch would be the foundation to further unify the behaviour of objects within the language, especially those which are speed-critical.) Possibly we can agree on this: * You confirm that the issue is a limitation in the current implementation, concrete: * Limitation: a redefined initialize method is *not* called during "literal instantiation" * You confirm that you will consider to apply a patch, under the condition that the patch * does not introduces a performance loss (or at least only a minimal one, e.g. < 1%) * does not break existent behaviour (compatibility) * You place the issue back on an "Standby" / "Halted" / "Feedback" state (other than "Rejected") And then I can go on to work on a solution/patch. ---------------------------------------- Bug #4893: Literal Instantiation breaks Object Model http://redmine.ruby-lang.org/issues/4893 Author: Lazaridis Ilias Status: Rejected 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