On Wed, 22 Jan 2003, Mauricio Fern?ndez wrote:

<snip>
> >   module M
> >     attr_accessor :x
> >     @x = 42
> Doesn't refer to the same thing!
>  The former will be an iv. of objects extended with M _or_
> instanciated from classes that include M.
>  The later is a module instance variable, ie, an instance variable
> associated to the 'M' object (that of class Module).
> >   end
> >
> >   class Foo; include M; end
> >
> >   p Foo.new.x  # >> nil
>
> Because it's not the same @x!
<snip>

that was my point.

<snip>
> irb(main):001:0> module M
> irb(main):002:1>  class << self; attr_accessor :x; end
> irb(main):003:1> end
> nil
> irb(main):004:0> M.x = 1
> 1
> irb(main):005:0> M.x
> 1
<snip>

didn't know you could do that...

<snip>
> The following won't work:
>
> irb(main):013:0> class Foo; include M; end
> Foo
> irb(main):014:0> Foo.x
> NameError: undefined method `x' for Foo:Class
>         from (irb):14
> irb(main):015:0> Foo.new.x
> NameError: undefined method `x' for #<Foo:0x4026360c>
>         from (irb):15
<snip>

yes.  all the more reason this idea :

<snip>
> > And if I leave it as a module it could be mixed into a class later (though
> > that's not how I'm using it now) and all of the 'module instance
> > variables' would also end up in the class it was mixed into....
<snip>

will not work.

<snip>
> The only ways to access module instance variables are through the
> accessors and instance_eval, AFAIK.
<snip>

AFAIK -> ???

-a

-- 

 ====================================
 | Ara Howard
 | NOAA Forecast Systems Laboratory
 | Information and Technology Services
 | Data Systems Group
 | R/FST 325 Broadway
 | Boulder, CO 80305-3328
 | Email: ahoward / fsl.noaa.gov
 | Phone:  303-497-7238
 | Fax:    303-497-7259
 ====================================