Y at-il une meilleure façon de le faire que:Modification du contenu d'une fermeture
|aBlock|
aBlock := [3+2].
aBlock := Object readFrom: (a printString copyReplaceAll: '3' with: '2').
?
EDIT Ce code était juste un exemple, qu'en des choses comme:
[:something |
something checkSomethingElse ifNil:
[whatever]
ifNotNil:
[something getSomethingDone]]
Où maintenant je veux checkAnotherThing au lieu de checkSomethingElse.
ou:
[:oneParameter :anotherParameter |
oneParameter doSomethingWith: anotherParameter]
Où maintenant je veux ajouter un troisième paramètre et:
[:oneParameter :anotherParameter :yetAnotherParameter |
oneParameter doSomethingWith: anotherParameter and: yetAnotherParameter]
Pourquoi faites-vous cela? – mathk
Parce que, dans Smalltalk, je peux: P –
Vous pouvez utiliser #perform: et co. changer la méthode de test. D'où: '[: quelque chose: selectorCheck | (quelque chose effectuer: selectorCheck) ifNil: [] ...] '. – mathk