Hi –
On Sun, 10 Sep 2006, Sam D. wrote:
def Example.select…
It won’t allow me to declare the types and gives me a syntax error. Any
help would be appreciated. Aren’t these just class variable
declarations and should be available through the class?
You’re confusing class variables with constants, and constants with
methods 
Class variables (@@var) are variables with a scope that includes
- the class in whose scope they were created
- all descendants of that class
- all instances of any of those classes
What class variables don’t have is any implication for methods; that
is, when you assign to a class variable, you’re just assigning to a
variable, not creating any methods that either get or set the value of
that variable.
If you want such methods, you have to write them:
class C
def self.cvar_x # access the cvar from the class
@@x
end
def cvar_x # access it from instances of the class
@@x
end
end
or create/use a facility for doing so, like the “cattr_*” methods that
are used internally in Rails.
By the way, the somewhat strange behavior of “class variables” – in
particular, that they’re not actually class-specific, but are more
class-hierarchy-specific – is due to change in future versions of
Ruby. Then there are people like me, who think class variables cause
(and will continue to cause, even with that change) much more trouble
than they’re worth, and wish they would go away entirely. But I don’t
think Matz is in that camp 
David
–
David A. Black | [email protected]
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org