[Newbies] Referencing a variable?
bert at freudenbergs.de
Thu Dec 3 12:05:18 UTC 2009
On 03.12.2009, at 12:59, Amir Ansari wrote:
> But I'd like to reuse the code as much as possible, so I'd prefer to do something like this:
> element := 'title'.
> choice := myLibrary collect: [:each | each element].
element := #title.
choice := myLibrary collect: [:each | each perform: element].
Note that this sends the "title" message. There is no way to directly access an instance variable from outside the object. Objects in Smalltalk are true objects, not data structures. The code above only works if you implemented a "title" method that returns the instance variable.
- Bert -
More information about the Beginners