I find that modules are good to add behaviour to an object like Enumerable but I don't find them practical as a namespace holder.
Including is an all or nothing operation. In your first example #is_spam? is now also a public method of MyOtherClass. The other issue with module includes is that method name collisions are also much harder to debug.
I also like your second example but I think it would be clearer if :spam_checker had a dedicated semantic. Something like:
class Module
def import(name, obj); define_method(name) { obj }; protected(name); end
end
Including is an all or nothing operation. In your first example #is_spam? is now also a public method of MyOtherClass. The other issue with module includes is that method name collisions are also much harder to debug.
I also like your second example but I think it would be clearer if :spam_checker had a dedicated semantic. Something like: