[squeak-dev] I am missing userful functionality?
Igor Stasenko
siguctua at gmail.com
Wed Sep 22 22:02:49 UTC 2010
Hello, guys
i want to do a simple thing, which can be expressed by following:
oldClass replaceWith: newClass migrateInstances: [:inst |
... ]
In my case, first, i installing a WeakFinalizationRegistry class,
and then want to replace an old WeakRegistry class with it,
silently and painlessly.
I end up with following script:
| old new oldClass newClass |
old := OrderedCollection new.
new := OrderedCollection new.
"migrate instances"
WeakRegistry allInstancesDo: [:registry | | newr |
old add: registry.
newr := WeakFinalizationRegistry basicNew initialize.
registry migrateTo: newr.
new add: newr ].
old asArray elementsForwardIdentityTo: new asArray.
"replace the class"
oldClass := WeakRegistry.
newClass := WeakFinalizationRegistry.
Smalltalk forgetClass: #WeakFinalizationRegistry logged: false.
newClass superclass removeSubclass: newClass.
newClass setName: #WeakRegistry.
oldClass becomeForward: newClass.
--
it looks a bit hackish, and i wonder how to do that in more 'standard' way.
Initially replacing classes was:
oldClass removeFromSystem.
newClass rename: #WeakRegistry
the problem with that, is that all compiled methods , which was
referring to old class through association,
still using it, and to get rid of them i have to recompile them.
--
Best regards,
Igor Stasenko AKA sig.
More information about the Squeak-dev
mailing list
|