reflection
Bert Freudenberg
bert at impara.de
Tue Jul 18 14:13:56 UTC 2006
Am 18.07.2006 um 16:11 schrieb Bert Freudenberg:
>
> 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.
Oh, actually you can even use methodHeaderFor: to get the correct arg
names.
- Bert -
More information about the Squeak-dev
mailing list
|