Robert Klemme
6/6/2007 12:14:00 PM
On 06.06.2007 12:57, dblack@wobblini.net wrote:
> Hi --
>
> On Wed, 6 Jun 2007, Robert Klemme wrote:
>
>> On 06.06.2007 03:24, Daniel Waite wrote:
>>> What I got most from it was its *incredibly thorough* explanation of
>>> the concept of 'self' in Ruby. Moments after finishing the chapter on
>>> self I ran to _why's creature code and, line by line, explained
>>> exactly what it was doing. I was so proud of myself. :)
>>
>> You make it sound as if there was something complex about "self".
>> Makes me wonder whether I am missing something about "self". As far
>> as I can see "self" is an ordinary variable with these additional
>> properties:
>>
>> - it is automatically set to the current receiver and it cannot be
>> altered by Ruby code
>>
>> - it is implicitly used for method invocations without an explicit
>> receiver and for instance variable access
>>
>> Did I miss anything?
>
> Only the fact that in practice, grasping self is a stumbling-block for
> a lot of people. In addition to just getting the concept of a
> "default object", which is not always easy, there's the question of
> where and when self changes, which can be confusing because it
> sometimes overlaps with local scope but not always.
This reminds me of the headaches I had when confronted with OOP the
first time. That's quite a few years ago now and OOP has become my
second nature (or so) - that's probably the reason why I did not find
anything strange about "self". But true, for somebody relatively new to
OOP this might be considerably harder. I had forgotten that. But it's
good to be reminded of this once in a while.
> So I wanted to explain (and document and demonstrate) both self and
> scope pretty thoroughly. Almost anything in the language can probably
> be reduced to a couple of defining phrases, but just saying (for
> example) that a class method is a singleton method of a class object
> doesn't actually make everyone understand or feel confident about
> applying the concepts involved. People really do learn in different
> ways :-)
Sure. I didn't want to question the explanation (haven't even read the
book as I am not doing any Rails), I was just curious whether I missed
something. Thank you for your explanation!
Kind regards
robert