Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the search for the meaning of "self"

Tags:

smalltalk

In smalltalk exists the "workspace" environment. BY definition,"self" points to the object inside which the current method is executing. But how am I to understand "current method" when I type code snippets inside the workspace window? There is no current object running any method or I missed something.Anyone can help?

like image 675
Sharphawk Avatar asked Feb 01 '13 18:02

Sharphawk


2 Answers

You can debug the code you execute and you will see that you end up executing a temporary method on an object. For instance in Pharo the workspace DoIts create a method on UndefinedObject (nil). So here self will refer to nil.

like image 166
camillobruni Avatar answered Oct 31 '22 14:10

camillobruni


Try this experiment: type 'self' into a workspace, select it, and select "print it" from the context menu. This will show you what object self is bound to.

In most Smalltalks, self will be nil.

like image 45
Colin Putney Avatar answered Oct 31 '22 14:10

Colin Putney