Rob Rypka wrote: >do you have an example of a task for which you want to use >metaclasses? > > What if you're trying to build a <a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431.22">factory factory factory</a>? >Hmmm. Here is what I want: > >module M > # magic for #foo, #bar >end > >class C > include M > # should do the equivalent of: > # def C.foo(n); @foo = n; end > # def bar; self.class.iv_get "@foo"; end > foo 55 # >end > >C.new.bar #=> 55 > You gotta do a little extra work for that -- a module gets included as instance methods if you use 'include', or class methods if you use 'extend' (due to that singleton mojo). Override that: module M def self.included(mod) mod.extend ClassMethods end def bar; self.class.instance_variable_get "@foo" end module ClassMethods def foo(n) @foo = n end end end class C include M foo 55 end p C.new.bar __END__ Browse through Ara's posts for some more examples of this. Devin