Sha256: 67a064535c44f81a5c88b27e998503175e356b1c77ec54832b183a9a846c869f
Contents?: true
Size: 824 Bytes
Versions: 29
Compression:
Stored size: 824 Bytes
Contents
module Shaddox class Settings < Hash def method_missing(meth, *args, &blk) name = meth.to_s return evaluate(self[meth]) if name.size == 1 # Ruby 1.8.7 doesn't let you do string[-1] key, suffix = name[0..-2].to_sym, name[-1..-1] case suffix when '=' self[key] = args.first when '?' include? key when '!' raise Error, "Setting :#{key} is not set" unless include?(key) evaluate self[key] else evaluate self[meth] end end def evaluate(value) if value.is_a?(Proc) value.call else value end end end module SettingContainer def init_settings(default_settings = {}) @settings = Settings.new.update(default_settings) end # Hook to loop up values in @info def method_missing(meth, *args, &blk) @settings.send meth, *args end end end
Version data entries
29 entries across 29 versions & 1 rubygems