From: Jeremy Henty Date: 2007-02-19T03:10:08+09:00 Subject: Re: Why should initialize_copy verify the class of the original? On 2007-02-18, SonOfLilit wrote: > I can call initialize_copy too, here: > > object.initialize_copy Well, actually you *can't*: ==> NoMethodError: private method `initialize_copy' called for ... :-) but I take your point (and you can work round "private" with #instance_eval ). But can it ever be called with an object of the wrong type unless the user explicitly does so? > If $SAFE isn't used (which is mostly the case), every bit of code can > do ANYTHING to the program state. That's true for Ruby variables, method calls etc., but hopefully we can ensure the C internals are not corrupted. I was thinking I could at least rely on the method being called with objects of the right type, but as you pointed out that's not true. > So that initialize_copy sanity test makes sense (personally, I'm not > sure I would've done it, I didn't do it either when I implemented color classes for Ruby/FLTK. I haven't managed to get a segfault out of it, but I can certainly corrupt objects. One more for the bug list... Thanks for the answer, I'm a little embarrassed not to have thought of it before posting. Jeremy Henty