From: transfire@... Date: 2006-05-28T11:33:48+09:00 Subject: Re: modularizing class methods [LONG] Interesting approach. It's a little bit of a misnomer mind you, becasue you have taken over the include processes such that you are not actually including module definitions, but rather are defining code in the base class itself. In other words, while your class will report ancestors of NameFields and AddressFields, there are actually no methods defined in those modules. I have seen another common way of doing this: module NameFields def included( base ) base.class_eval %{ field :first, :last, :middle } end end This works too, of course, though I think your technique is more clever and worth additional study. Nonetheless there is still the fact in either case of being real module inclusion. Maybe it would be better not to use the include mechinism. Ie. just create a different module method to do the work. You could still go about it the same way, but just use a different method other than #include. Here is an example of what I came up with some time ago. class Module def package( name, &block ) @__package__ ||= {} return @__package__ unless block_given? @__package__[name.to_sym] = block end def provide_features( base, *selection ) selection.each do |s| base.class_eval( &@__package__[s.to_sym] ) end end def use( package, *selection ) if String === package or Symbol === package package = constant(package) end package.provide_features( self, *selection ) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # require 'test/unit' class TCModule < Test::Unit::TestCase module MyPackages package :foo do def foo "yes" end end end class Y use MyPackages, :foo end def test_package y = Y.new assert_equal( "yes", y.foo ) end end Though it may need some tweaking to work for your usecase, I suspect something like this woud do the job nicely. In any case I'm gogin to give your code some more thought. Please let us know if you improve upon it. T.