Sha256: 7234f5098a5e53363bc5562e12618337fdd5348e58c85ab63c3f15496b28cc7d

Contents?: true

Size: 348 Bytes

Versions: 1

Compression:

Stored size: 348 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
defined-by-0.0.5 lib/defined-by/define_module.rb