lib/hashr.rb in hashr-0.0.4 vs lib/hashr.rb in hashr-0.0.5
- old
+ new
@@ -2,10 +2,12 @@
autoload :EnvDefaults, 'hashr/env_defaults'
TEMPLATE = new
class << self
+ attr_accessor :raise_missing_keys
+
def define(definition)
@definition = definition
end
def definition
@@ -31,14 +33,19 @@
when '?'
!!self[name.to_s[0..-2].to_sym]
when '='
self[name.to_s[0..-2].to_sym] = args.first
else
- self[name]
+ read(name)
end
end
protected
+
+ def read(key)
+ raise(IndexError.new("Key #{key.inspect} is not defined.")) if !key?(key) && self.class.raise_missing_keys
+ self[key]
+ end
def include_modules(modules)
Array(modules).each { |mod| meta_class.send(:include, mod) } if modules
end