On 1/20/06, dblack / wobblini.net <dblack / wobblini.net> wrote:
> >> Does this help at all?
>
> [...]
>
> > Hmm. Not sure yet. While I try to wrap my head around what's going on
> > with the const_missing and const_get magic above, here is the short
> > script I wrote to try and simulate the real-world problem I'm trying
> > to solve. Note that the derived class  (A) is trying to access a class
> > variable and not a constant as in your example.
>
> Whoops, I misread.
>
> > module Foo
> >  class Bar
> >    @@classvar = "Boo!"
> >  end
> > end
> >
> > module FooBarHelper
> >  class << Foo::Bar
> >    def amethod
> >      puts  @@classvar
>
> The class variables of Foo::Bar's singleton class are not the same as
> those of Foo::Bar, so you'd want to avoid opening up the singleton
> class.

Ah, is that what I'm doing? ;) Must reread the pickaxe chapters on
Ruby's object system...

> You can do this instead:
>
> class Foo::Bar
>    def self.amethod
>      puts @@classvar
>    end
> end

Right. This was my interim solution. However, as mentioned previously
in this thread, Foo::Bar is a third party gem (the ActiveLDAP module,
just to add some context to all this), and I want to avoid having to
maintain my additions to this everytime the lib gets a new release.

>
> As things stand there's no need for the FooBarHelper module at all:

Yes, unless I'm trying to avoid directly modifying a third party
module as outlined above.
Just to add a bit more context to what I'm trying to achieve here, the
class variable I'm trying to access is a ruby-ldap connection object.
If my only option is to modify ActiveLDAP itself as you've suggested
here, then that's the way I'll go. Is that my only option? Thanks for
your responses so far.

jh

--
James Hughes
Web application developer
Centre for Health Services and Policy Research
Vancouver, BC