Sha256: 3f383e9baead73cd5d3368f67ec864f7c83631c07291fe427bd474ee3732185b

Contents?: true

Size: 363 Bytes

Versions: 1

Compression:

Stored size: 363 Bytes

Contents

def define_class(name, superclass = Object, &block)
  name = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  superclass = superclass.to_s.gsub(/^:*/, "::")
  eval("class #{name} < #{superclass}; end")
  clazz = eval(name)
  clazz.unloadable if clazz.respond_to?(:unloadable)
  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.6 lib/defined-by/define_class.rb