From: dblack@... Date: 2006-01-21T08:23:02+09:00 Subject: Re: Inserting Hi -- On Sat, 21 Jan 2006, James Hughes wrote: > On 1/19/06, Paul Brannan wrote: >> >> You can also create a mixin and extend Foo::Bar with the mixin. If you >> do this, instance methods in the mixin will be available as class >> methods in Foo::Bar and derived classes. > > Ok, I'm doing something like the following: > > module FooBarHelper > > class << Foo::Bar > # some instance methods, which reference class vars from Foo::Bar > end > end > > Then, in classes A and B I do "include FooBarHelper". When I run this > I get "uninitialized class variable" errors for the Foo::Bar's class > vars. > > So, to state my question again, how can I extend the functionality of > the Foo::Bar library (short of hacking it's source directly), while > still maintaining access to the class variables defined in Foo::Bar? > Is this even possible? Does this help at all? module Foo class Bar def self.meth puts "Class method of Foo::Bar" end X = "Constant of Foo::Bar" end end module Needed def self.const_missing(c) Foo::Bar.const_get(c) end def needed_method puts "This is a needed method" puts X end end class A < Foo::Bar extend Needed end puts A::X A.meth A.needed_method David -- David A. Black dblack@wobblini.net "Ruby for Rails", from Manning Publications, coming April 2006! http://www.manning.com/books/black