Sha256: 6af39433841df481c6b92734527ac8466069e2636a307746a0eacf32e3729543
Contents?: true
Size: 1003 Bytes
Versions: 12
Compression:
Stored size: 1003 Bytes
Contents
module MotionPrime class Config def initialize(attributes = {}) @attributes = attributes || {} end def [](key) @attributes.has_key?(key.to_sym) ? fetch(key) : store(key, self.class.new) end def store(key, value) @attributes[key.to_sym] = value end alias :[]= :store def fetch(key) @attributes[key.to_sym] end def nil? @attributes.empty? end alias :blank? :nil? def has_key?(key) !self[key].is_a?(self.class) end def to_hash @attributes end class << self def method_missing(name, *args, &block) @base_config ||= self.new() @base_config.send(name.to_sym, *args, &block) end end def method_missing(name, *args, &block) if block_given? yield self[name] else name = name.to_s if /(.+)=$/.match(name) return store($1, args[0]) else return self[name] end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems