How can I send a block and its argument to a method ? so the method receive the block and the block receives the argument and I run the block in the method iteslf...
相关问题
- Simple class definition error in smalltalk
- Which Smalltalk object should be passed to a C fun
- Squeak(smalltalk) subSrings ignores empty strings
- Smalltalk variables: why should I declare them?
- How to manage 2d array in Smalltalk?
相关文章
- Implementation Strategies for Object Orientation
- What is the difference between Seaside programmmin
- How to copy several Monticello commits from local
- Smalltalk ReferenceStream has problems with new in
- Is it possible to write shell command within Pharo
- Draw table in Pharo
- Double dispatch in Pharo
- How can I get all the methods in a Protocol?
Just pass the block and its argument to the method as separate arguments. Then send
#value:
to the block to pass the argument to the block. E.g.For an example have a look at the
sort:
method ofOrderedCollection
(you'll find the block evaluated finally inSortedCollection>>mergeFirst:middle:last:into:by:
).Inside a method that accepts a block as parameter, you would evaluate the block, this means call it with parameters and use the result. Not so much try to "access the argument of the block".
You would e.g. send a message with a block as parameter to a collection of colors to sort it by luminance:
results in: "an OrderedCollection(Color black Color red Color yellow Color white)"