reflection
Bert Freudenberg
bert at impara.de
Tue Jul 18 14:11:00 UTC 2006
Am 18.07.2006 um 15:12 schrieb Niko Schwarz:
> I want to write a Wikipedia article about "Jacketing" and I thought
> a cool squeak snippet would show both how cool I am and how
> jacketing works. Unfortunately, the snippet is growing. I wanted to
> write it neatly short, like this (no callback:)
>
> unblock: selector
> "Macht den blockierenden Aufruf selector unblockierend."
> |bs|
> bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird
> umbenannt"
>
> self
> addSelector: bs
> withMethod: (self methodAt: selector).
> self addSelector: selector
> withMethod: (self class compile: '[self perform: selector
> withArgs:args] fork')
>
>
> but as you probably noticed already, withArgs:args is not quite
> possible this way. Is there a short line of code that deals with it?
Untested, but might work:
unblock: selector
"Macht den blockierenden Aufruf selector unblockierend."
|bs|
bs := (#blocking , selector) asSymbol. "Der alte Aufruf wird umbenannt"
self
addSelector: bs
withMethod: (self methodAt: selector).
self addSelector: selector
withMethod: (self class compile:
(self standardMethodHeaderFor: bs),
'[self ', (self standardMethodHeaderFor: selector), '] fork')
You do not need to perform if you are compiling anyway. Note that
that you need to construct 'bs' differently if selector is an operator.
- Bert -
More information about the Squeak-dev
mailing list
|