[Newbies] perform withArguments
bert at freudenbergs.de
Tue Apr 24 03:59:09 UTC 2012
On 23.04.2012, at 07:58, OrgmiGeek wrote:
> I've read the sparse documentation on 'dynamic message' calls and I've
> experimented a lot and still cannot figure out how to do something that
> should be simple:
> I want to build a message like this:
> cellObject cellLock: aBoolean
> where cellObject is to look like: cell1, cell2, cell3 ..., or cell9
> I can build up cellObject like this:
> self perform: ('cell', cellNumber asString) asSymbol
> but I can't figure out how to build the full message with the key selector
> "cellLock:", and the value 'aBoolean'.
> I've tried everything I can think of based on the terse documentation, and
> anything I can find on the internet, which isn't much (including this
> Any help would be appreciated.
So if I understand correctly you want to do something equivalent to this:
cell1 cellLock: true.
cell2 cellLock: true.
cell3 cellLock: true.
... etc ...
Yes? If so, then perform is not what you are looking for. Perform lets you assemble the message selector, but not the receiver of the message. The Right Way to do this would be to have an Array of cells. Arrays are a collection of objects, and individual objects can be accessed by index. So if "cells" was an array of your cell objects, you could write
(cells at: 1) cellLock: true.
(cells at: 2) cellLock: true.
(cells at: 3) cellLock: true.
... etc ...
but also iterate over all of them:
1 to: 10 do: [:i | (cells at: i) cellLock: true]
Does that make sense?
- Bert -
More information about the Beginners