B
Bill Kelly
From: "Sean O'Dell said:You're wrong on that. It wouldn't crash Ruby to change the class of an
object. Objects already change their class when you turn them into
singletons. Changing it to any class of your choosing would be even simpler,
since creating a singleton involves inheriting all the old class methods;
changing a class wouldn't require all that work.
Supposed an object's class were changed to a different class
which was itself (or whose ancestor(s) were) implemented in 'C'
code. Something that expects that once it's initialized it
can go ahead and rely on its class invariants pointing to real
operating system file handles, window handles, etc.
Like, hypothetically,
"hello".class = OpenGLCanvas
"hello".class = IO
...or whatever. For example:
x = "hello"
x.class = OpenGLCanvas
x.PushMatrix()
kind of thing.
Should we expect a hard crash here? If so, is that OK because
it's "programmer error" and not really Ruby's fault?
I haven't done enough Smalltalk to know what #become would do
in such situations...
Regards,
Bill