George Moschovitis wrote:
> Hello everyone,
> 
> the following idiom is very useful:
> 
> module MyModule
>     def self.append_features(base)
>         super; base.extend(ClassMethods)
>     end
> 
>     module ClassMethods
> 
>         def a_class_method
>             puts 'class'
>         end
>     end
> end
> 
> class MyClass
>     include MyModule
> end
> 
> MyClass.a_class_method # => 'class'
> 
> I think it would be a good idea to have some form of syntactic sugar
> for this idiom in Ruby 1.9/2.0
> 
> Any ideas ?

Don't wait :)

class Module
private
   def when_included_provide_class_methods(&bl)
     unless @__class_methods_module
       @__class_methods_module = Module.new

       def self.append_features(base)
         super
         base.extend(@__class_methods_module)
       end
     end

     @__class_methods_module.class_eval(&bl)
   end
end

module MyModule
   when_included_provide_class_methods {
     def a_class_method
         puts 'class'
     end
   }
end

class MyClass
   include MyModule
end

MyClass.a_class_method # => 'class'