Hi,

In message "Re: CORE - Literal Instantiation breaks Object Model"
    on Fri, 10 Jun 2011 03:40:27 +0900, Ilias Lazaridis <ilias / lazaridis.com> writes:

|The behaviour of the class String has been altered, whilst using the
|standard mechanisms of the Object Model.
|
|To my huge surprise, although the li_string has been instantiated as
|an object of class String, the new initialize method was not called.
|
|This is essentially a defect, as the consistency of the Object Model
|breaks.

You don't have to teach me about Ruby's object model.  String objects
for literals are already created in the compile time, which is far
before you redefine the initialize method.  The individual string
objects from literals are just copy of the already allocated and
initialized objects.  The whole purpose of the initialize method is to
initialize newly created objects, as the name suggests.  I don't feel
any need to call the (redefined) initialize method for string
literals, that already initialized at the compile time.  Even if you
can use it to track object creation, it's only a side-effect.  I am
not going to change the language (or its object model) to fit your
purpose better.

In general, if you want a perfect language that satisfies every random
ideas popping in your mind, you'd better design your own language,
rather than trying to hijacking existing one.

|The questions are:
|
|b) Is there any way to track (intercept) the instantiation of objects
|(especially those instantiated from literals)
|  1) without a C-level extension
|  2) with a C-level extension

If you don't care about performance, you can investigate
ObjectSpace#each_object.  Note that JRuby turns off the method by
default for performance reason.  If you care about performance, I am
afraid that you have to modify the interpreter itself.

							matz.