Skip to content

Commit f33b8d5

Browse files
committed
creating a canHandle: arity method
1 parent 33067bc commit f33b8d5

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Class {
2+
#name : 'MpHandlerTest',
3+
#superclass : 'TestCase',
4+
#category : 'MethodProxies-Tests',
5+
#package : 'MethodProxies-Tests'
6+
}
7+
8+
{ #category : 'tests' }
9+
MpHandlerTest >> testCanHandleMethodWithArity [
10+
11+
self assert: (MpHandler new canHandle: 5).
12+
self deny: (MpHandler new canHandle: 6)
13+
]

src/MethodProxies/MpHandler.class.st

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ MpHandler >> beforeMethod [
114114

115115
]
116116

117+
{ #category : 'as yet unclassified' }
118+
MpHandler >> canHandle: arity [
119+
120+
^ arity < 6
121+
]
122+
117123
{ #category : 'evaluating' }
118124
MpHandler >> insteadExecutionWithReceiver: anObject [
119125
^ self insteadExecutionWithReceiver: anObject arguments: {}
@@ -149,12 +155,12 @@ MpHandler >> insteadExecutionWithReceiver: anObject with: arg1 with: arg2 with:
149155
]
150156

151157
{ #category : 'as yet unclassified' }
152-
MpHandler >> overridesAfterMethodFor: anInteger [
158+
MpHandler >> overridesAfterMethodFor: arity [
153159

154160
| argKeywords |
155161

156-
anInteger > 5 ifTrue: [ ^ false ].
157-
argKeywords := '' join: ((1 to: anInteger) collect: [ :i | 'with:' ]).
162+
(self canHandle: arity) ifFalse: [ ^ false ].
163+
argKeywords := '' join: ((1 to: arity) collect: [ :i | 'with:' ]).
158164

159165
^ (self class lookupSelector:
160166
(#afterExecutionWithReceiver: , argKeywords, 'returnValue:') asSymbol)
@@ -169,25 +175,25 @@ MpHandler >> overridesBeforeMethod [
169175
]
170176

171177
{ #category : 'as yet unclassified' }
172-
MpHandler >> overridesBeforeMethodFor: anInteger [
178+
MpHandler >> overridesBeforeMethodFor: arity [
173179

174180
| argKeywords |
175181

176-
anInteger > 5 ifTrue: [ ^ false ].
177-
argKeywords := '' join: ((1 to: anInteger) collect: [ :i | 'with:' ]).
182+
(self canHandle: arity) ifFalse: [ ^ false ].
183+
argKeywords := '' join: ((1 to: arity) collect: [ :i | 'with:' ]).
178184

179185
^ (self class lookupSelector:
180186
(#beforeExecutionWithReceiver: , argKeywords) asSymbol)
181187
methodClass ~= MpHandler
182188
]
183189

184190
{ #category : 'as yet unclassified' }
185-
MpHandler >> overridesInsteadMethodFor: anInteger [
191+
MpHandler >> overridesInsteadMethodFor: arity [
186192

187193
| argKeywords |
188194

189-
anInteger > 5 ifTrue: [ ^ false ].
190-
argKeywords := '' join: ((1 to: anInteger) collect: [ :i | 'with:' ]).
195+
(self canHandle: arity) ifFalse: [ ^ false ].
196+
argKeywords := '' join: ((1 to: arity) collect: [ :i | 'with:' ]).
191197

192198
^ (self class lookupSelector:
193199
(#insteadExecutionWithReceiver: , argKeywords) asSymbol)

0 commit comments

Comments
 (0)