Sha256: d6ebc8b709f78e992eb41bf7e331860b4715089292b6bda4dfb842ebc80629ff

Contents?: true

Size: 432 Bytes

Versions: 1

Compression:

Stored size: 432 Bytes

Contents

require "namespaced_mixin/version"

module NamespacedMixin
  module ClassMethods
    def namespace(name, as:)
      namespace = as.to_s

      namespaced_class = name.to_s.split('::').inject(Object) {|o,c| o.const_get c}
      cls = Class.new{
        include namespaced_class
      }.new

      define_method("#{namespace}") do
        cls
      end
    end
  end

  def self.included(base)
    base.extend(ClassMethods)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
namespaced_mixin-0.1.0 lib/namespaced_mixin.rb