How to intercept instvar write - MetaLinks + anonymous subclass problem

Petr Fischer petr.fischer at me.com
Fri Feb 1 21:23:00 EST 2019


> is possible to intercept (before writeú all instance variable writes on every existing objects?
> 
> I found a discussion here:
> http://forum.world.st/Is-it-possible-to-follow-an-object-through-a-computation-td5092459.html
> 
> Known solutions:
> ....
> 3) Metalinks - it's based on intercepting method calls, right? But I need to intercept direct instance variable write, so probably not possible

Ok, I learned more about MetaLinks and it's perfectly possible to intercept instance variable writes via. installing MetaLink into object instance (cool) - then I can intercept instvar write, but one problem immediately occurs:
when installing MetaLink into object instance, an original object class is exchanged to anonymous subclass of the original class - and because typical #= method is implemented like:

=
	self == anObject
		ifTrue: [ ^ true ].
	self class = anObject class
		ifFalse: [ ^ false ].
	...

then most of #= comparisons in application logic is broken due to "self class = anObject class" part.

Is there any way to solve this problem?

Thanks! pf



More information about the Pharo-users mailing list