From: Paul Brannan Date: 2004-09-08T23:42:09+09:00 Subject: Re: Marshal and allocating objects On Wed, Sep 08, 2004 at 11:31:04PM +0900, ts wrote: > >>>>> "P" == Paul Brannan writes: > > P> Even if allocate is used, this won't work. The lookup for the class is > P> failing before allocate is called. > > Well, if I've well understood he want that Marshal use the same algorithm > than ruby when it find a constant name. That's the way I read it. > Actually marshal just look is the constant is defined, when ruby can call > #const_missing when he write `M.allocate' Right, which is why const_missing never gets called. Making Ruby call allocate doesn't solve the problem, because Ruby is checking to see if the constant exists (in rb_path2name) before trying to look it up. > P> class Foo > P> SOME_CONSTANT = 1 > P> def foo > P> return SOME_CONSTATN > P> end > P> end > > P> my code will no longer break, but will silently do the wrong thing. > > Not understood, sorry In order to demonstrate why I do not think const_missing should be defined for class Object, I intentionally misspelled "SOME_CONSTATN". Before const_missing was defined I would get an exception here, whereas after Stephen's version of const_missing is in place, I will instead get a new class. Even with well-written unit tests, finding this misspelling can be a challenge. Paul