Hi --

On Sat, 9 Jun 2007, Dale wrote:

>
> I'd like to make a class constant using a module -- I cannot use <
> because I am extending unit_test. -- Here's the idea:
>
> module One
>   @@constant="constant"
> end

That's not a constant; it's a class variable (completely different
thing).

> module Two
>   def work
>      puts(@@constant)
>   end
> end
> class Constant_work
>   include One
>   include Two
> end
> Constant_work.new.work
>
> IRB gives me:
> NameError: uninitialized class variable @@constant in Two
>
> How can I get what I want to happen?

   module One
     C = "constant"
   end

   module Two
     include One
     def work
       puts C
     end
   end

   class ConstantWork
     include Two
   end

   ConstantWork.new.work    # constant

Constant identifiers begin with an uppercase letter.  The @@ thing is
a class variable, which is a very different (and much less useful)
construct.


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)