def define_module(name, &block) name = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } parts = name.split("::") parts.each_with_index do |part, index| sub_name = parts[0..index].join("::") eval("module #{sub_name}; end") end clazz = eval(name) clazz.unloadable if clazz.respond_to?(:unloadable) clazz.class_eval(&block) if block_given? clazz end =begin def add_module(name, &block) define_module(name).class_eval do class << self; self; end.send(:define_method, :included) { |base| base.class_eval(&block) } end end =end