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.

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 :-)


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)