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.class_eval(&block) if block_given? clazz end