In Squeak, how to wrap each dispatch method?

I created a class, and in this class I have a method 'sendMessage: to: withArgs:' that receives an object, message and an array of arguments. This method is used to send messages to an object and execute some algorithm. To use this method, I need to create an instance x of the class that I created and do something like x sendMessage: '+' to: '7' withArgs: '# (5)'. The result of this sends a “+” message to object 7 with parameter 5, as well as some things that my algorithm does. But I want the algorithm to be used in every method call, that is, 7 + 5 will call my "sendMessage: to: withArgs:". How can i do this? Or at least is there something called by every method sent to every object?

+2
source share
4 answers

Oddly enough, we just discussed it on the Squeak irc channel. Maybe take a look at ObjectViewer.

In your example, you want to intercept sending messages to SmallInteger. Oddly enough, ObjectViewer works with every BUT SmallInteger class.

So, to intercept sending messages to myObject, do this.

Create an Intercepter class, let it inherit ObjectTracer, perhaps. Changing doesNotUnderstand to something that helps you:

doesNotUnderstand: aMessage
   "do Mojo to aMessage as you describe it"

Then, to get your stuff, create your Intercepter:

myIntercepter := Intercepter on: myObject.

And then

myObject become: myInterceptor.
+2
source

In Squeak, see the ObjectTracer class. A class comment describes how to use it. You should be able to accomplish what you need, or at least use it as a model.

+2
source

.

, , , , , . Link.

+2

. , , " ". , , . , , Pharo, , , . ,

+1

All Articles