Skip to content

Instantly share code, notes, and snippets.

@mumez
Created December 14, 2014 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumez/59a3da9e4cc31a1165d1 to your computer and use it in GitHub Desktop.
Save mumez/59a3da9e4cc31a1165d1 to your computer and use it in GitHub Desktop.
SystemOrganization addCategory: #AdvMessageInterceptor!
ProtoObject subclass: #AdvMessageInterceptor
instanceVariableNames: 'originalObject'
classVariableNames: ''
poolDictionaries: ''
category: 'AdvMessageInterceptor'!
!AdvMessageInterceptor class methodsFor: 'instance creation' stamp: 'mu 12/13/2014 21:20'!
on: anOriginalObject
^self new xxxOriginalObject: anOriginalObject! !
!AdvMessageInterceptor methodsFor: 'system primitives' stamp: 'mu 12/13/2014 21:20'!
becomeForward: otherObject
"Primitive. All variables in the entire system that used to point
to the receiver now point to the argument.
Fails if either argument is a SmallInteger."
(Array with: self)
elementsForwardIdentityTo:
(Array with: otherObject)! !
!AdvMessageInterceptor methodsFor: 'system primitives' stamp: 'mu 12/13/2014 21:20'!
doesNotUnderstand: aMessage
aMessage transcriptOn: originalObject.
^aMessage sendTo: originalObject! !
!AdvMessageInterceptor methodsFor: 'actions' stamp: 'mu 12/13/2014 21:20'!
intercepted
^self! !
!AdvMessageInterceptor methodsFor: 'actions' stamp: 'mu 12/13/2014 21:20'!
quitIntercepting
self becomeForward: originalObject! !
!AdvMessageInterceptor methodsFor: 'accessing' stamp: 'mu 12/13/2014 21:20'!
xxxOriginalObject: anObject
originalObject := anObject! !
!Message methodsFor: '*AdvMessageInterceptor-logging' stamp: 'mu 12/13/2014 23:20'!
transcriptOn: receiver
Transcript cr;
show: ('a {1}({2}) >> {3}' format: {receiver class name. receiver identityHash. self selector})! !
!Object methodsFor: '*AdvMessageInterceptor-actions' stamp: 'mu 12/13/2014 23:32'!
intercepted
^AdMessageInterceptor on: self
! !
@mumez
Copy link
Author

mumez commented Dec 14, 2014

"Developing interceptor in Smalltalk"
http://qiita.com/mumez/items/72272fac093a2aaabbee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment