[Newbies] yourself

Marcus Denker denker at iam.unibe.ch
Thu Aug 31 15:49:57 UTC 2006


On 31.08.2006, at 17:35, Bakki Kudva wrote:

> Hi,
>
> I'm a bit confused about y ourself. I understand that the definition
> of yourself is ^self
> But when I browse Object and look at yourself: all I find is the
> description string..
> "Answer self."

> What happened to ^self? Where is the actual code implementing this?
>

self is the default return value. So if you return nothing special,  
the compiler
will add a ^self at the end.

A good rule is to make the ^self explicit as soon as it is important,  
thus
for our lecture (#yourself is covered in 04:
http://www.iam.unibe.ch/~scg/Teaching/Smalltalk/Slides/04Idioms.pdf )

we changed the implementation of #yourself to be

yourself
	"Answer self."
	^self

This is in 3.9

     Marcus


More information about the Beginners mailing list