On Mon, Apr 14, 2003 at 02:42:24PM +0900, Tim Bates wrote:
> Hi all,
> I have several classes in a module, thus:
> 
> module Example
>   class Ay
>   end
> 
>   class Bee
>   end
> end
> 
> I have a piece of data I want to share between classes Example::Ay and 
> Example::Bee, preferably without it being available to things outside the 
> module. What's the best way to do this? As a class variable of Example 
> doesn't seem to work, as I can't access this from within Ay or Bee...

Class variables are only available to a class and its descendants, so you
have to make both Ay and Bee inherit from a common ancestor:

module Example
  module Shared
    @@data = nil
  end

  class Ay
    include Shared
    def Ay.setit(x)
      @@data = x
    end
  end

  class Bee
    include Shared
    def Bee.putit
      p @@data
    end
  end
end

Example::Ay.setit(42)
Example::Bee.putit      #>> 42


Regards,

Brian.