Hi --

On Fri, 17 Aug 2007, Arno J. wrote:

> Hello,
>
> I would like to have a confirmation about the fact that singleton
> variables just don't have any meaning, or an explation about how to use
> them.
> An example to be sure that we are talking about the same thing :
>
> class A
>
>  @class_instance_variable
>
>  class << self  #or class << A
>
>    @singleton_variable # <- Can this be used/called elsewhere ?

Like all instance variables, it belongs to whatever object is 'self'
at the point where the instance variable appears, and multiple
references to the same instance variable in different contexts where
self is the same, will be references to the same instance variable.

>    def some_method
>      @class_instance_variable
>    end
>
>  end
>
> end

I don't find the term "singleton variable" very helpful. All the
variables in your example are just instance variables. Calling them
"class instance variables" is sometimes useful, since there are
contexts in which it might sound like you mean an instance variable in
a class's instance methods. But I'd be conservative about coining new
terms for instance variables that happen to occur in different
contexts.


David

-- 
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)