Daniel Schierbeck wrote:
> Yukihiro Matsumoto wrote:
> > Redundancy can be removed by some kind of meta programming.
>
> This could do the job:
>
>    class Module
>      def class_methods(&block)
>        @class_methods = block
>      end
>
>      def included(mod)
>        (class << mod; self; end).module_eval(&@class_methods)
>      end
>    end
>
>    module Mod
>      class_methods do
>        def foo
>          "FOO"
>        end
>      end
>
>      def bar
>        "BAR"
>      end
>    end
>
>    class Test
>      include Mod
>    end
>
>    Test.foo      #=> "FOO"
>    Test.new.bar  #=> "BAR"

Daniel! I think you actually make my point! Matz, see what Daniel has
done here? --dumping the class methods directly into the class. This is
the kind of thing I see happening in other peoples code.

This really has nothing to do with the *capability* to meta-code a
solution (I have done so myself, of coure), it's that people don't
fully understand what really needs to happen, or understand the
distinctinctive use of extend vs. include. It may seem "intuitive" for
you since you have a complete understanding of Ruby underthehood. But
it's far from intuitive for others.

BTW, Daniel, have a look as Facets' classmethods.rb or class_inherit.rb
for a better idea of how to do what you are suggesting.

T.