A fully transparent proxy implementation for Amber

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

A fully transparent proxy implementation for Amber

Nicolas Petton
Hey guys,

Just in case this can be useful to others, here's a 100% transparent
implementation of a proxy in Amber. It removed inherited methods on each
instance at initialization:

Proxy >> initialize
        super initialize.
        self inheritedSelectors do: [ :each | <self[each._asSelector()] = undefined> ]


Proxy >> inheritedSelectors
        | selectors methods |

        methods := self basicAt: 'inheritedMethods'.
        selectors := #().
        <for(var selector in methods) {selectors.push(selector)}>.

        ^ selectors
                reject: [ :each | self class methodDictionary keys includes: each ].


Proxy >> doesNotUnderstand: aMessage
        "Forward message sends here"

        ^ aMessage sendTo: anObject

Cheers!
Nico

--
Nicolas Petton
http://nicolas-petton.fr
Reply | Threaded
Open this post in threaded view
|

Re: A fully transparent proxy implementation for Amber

Bernat Romagosa
Beautiful!

2012/9/21 Nicolas Petton <[hidden email]>
Hey guys,

Just in case this can be useful to others, here's a 100% transparent
implementation of a proxy in Amber. It removed inherited methods on each
instance at initialization:

Proxy >> initialize
        super initialize.
        self inheritedSelectors do: [ :each | <self[each._asSelector()] = undefined> ]


Proxy >> inheritedSelectors
        | selectors methods |

        methods := self basicAt: 'inheritedMethods'.
        selectors := #().
        <for(var selector in methods) {selectors.push(selector)}>.

        ^ selectors
                reject: [ :each | self class methodDictionary keys includes: each ].


Proxy >> doesNotUnderstand: aMessage
        "Forward message sends here"

        ^ aMessage sendTo: anObject

Cheers!
Nico

--
Nicolas Petton
http://nicolas-petton.fr



--
Bernat Romagosa.