Re: Delegating class methods




On Mar 2, 2009, at 9:24 AM, lasitha wrote:
There is a school of thought that eigenclass [1] instance variables
are generally preferred over @@class_variables. Folks coming to ruby
from other languages often miss the distinction but you'll find many
exposés on this [2], including in the Pickaxe.

I personally like eigenclass variables - they provide all the
capability of class variables, fit elegantly into ruby's object model
and follow all the rules of instance variables. So i don't ever bother
with class vars.

I don't think I've ever seen the term 'eigenclass variables' used in
this way. Every object has instance variables. Classes are objects
and so they have instance variables. There is no need to talk about
eigen classes (or the more common term, singleton classes) when you
are talking about alternatives to class variables.

The main confusion with Ruby class variables comes from:
-- Ruby class variables have syntax similar to instance variables
but much different semantics
-- Ruby class variables are assumed to be analogous to C++ class
variables (or Java class variables) but that is the wrong
analogy. Ruby instance variables of class objects is the more
appropriate comparison.

It would be nice if there was a common term for 'instance variables
of class objects' but 'eigenclass variables' isn't it.

Gary Wright




.



Relevant Pages

  • Re: Class instance variable idiom
    ... I would also recommend to not use them. ... "class instance variables", but I've yet to experience any problems ... with class variables. ... In Ruby> 1.8, class variables are going to be somewhat more strictly ...
    (comp.lang.ruby)
  • Re: class initialize method not working ???
    ... Its not a ruby error. ... in the context of an object instance. ... Unitialized instance variables are nil by ... Output: self is MyClass ...
    (comp.lang.ruby)
  • Re: Class instance variable idiom
    ... I'm on record as saying that class variables are the thing I dislike ... behave that is different from constants or singleton (note the ... I've never been completely comfortable with the Ruby ... Inheritance is a power tool, ...
    (comp.lang.ruby)
  • Re: class initialize method not working ???
    ... Florian Gilcher wrote: ... Its not a ruby error. ... First, in #initialize, you refer to an instance variable called @dbs ... Unitialized instance variables are nil by ...
    (comp.lang.ruby)
  • Re: class initialize method not working ???
    ... I assume it's a compiler error (right term in Ruby?), ... context of an object instance. ... Output: self is MyClass ... their instances do not share instance variables, ...
    (comp.lang.ruby)