[Newbies] Understanding "self"

Mathieu Suen mathk.sue at gmail.com
Wed Jan 30 13:11:45 UTC 2008


Hi Andy,

The scope of the block is taken from were it is define not were it is  
evaluate.
If no then yo couldn't write code like this for example:

aCollection detect:[:each | self maxValue < each]

One solution to what you want could be to add a parameter:


aVar := AnotherObj new
aVar setBlockTo: [:arg | Transcript show: arg]
aVar block value: self.




On Jan 30, 2008, at 6:43 PM, Andy Burnett wrote:

> I am working through the SBE book ( which is really very good) and I  
> have been experimenting with using self in blocks.
>
> In simple terms I am doing something like:
> " within the initialisation of an object"
>
> aVar := AnotherObj new
> aVar setBlockTo: [Transcript show: self]
>
> Then I had a method in the first object which asked the second  
> object to show the value of its block.
>
> What I was expecting was for self to be defined in terms of the  
> object it was assigned to ie the second object. However it actually  
> returns tv details of the object the block was coded in
>
> Somehow I don't think I am explaining myself very well. But what I  
> want to know is how to think about self. Will it always point to the  
> object in which the method was actually written?
>
> Thanks
> AB
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

	Mth





More information about the Beginners mailing list