Module: Asbestos::ClassCollection::ClassMethods

Defined in:
lib/asbestos.rb

Instance Method Summary collapse

Instance Method Details

#class_collection(name, base = self) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/asbestos.rb', line 74

def class_collection(name, base = self)
  # this is a little nasty, the 'name' variable isn't available
  # in the scope of the eigenclass, so we have to class_eval
  # the eigenclass
  (class << base; self; end).instance_eval do
    extend ::Forwardable

    attr_accessor name
    def_delegators name, :[], :[]= if name == :all
  end

  Hash.new.tap do |hash|
    Asbestos.with_indifferent_access! hash
    base.instance_variable_set "@#{name}", hash
  end
end