diff --git a/README.md b/README.md index b6bcead..5d63bde 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Usage settings = Settings::Hash.new("config/settings.yml", "test") settings[:foo] #=> 123456 + settings.foo #=> 123456 ENV["RACK_ENV"] = "development" settings = Settings::Hash.new("config/settings.yml", ENV["RACK_ENV"]) diff --git a/lib/settings.rb b/lib/settings.rb index 7cd5322..7df13cd 100644 --- a/lib/settings.rb +++ b/lib/settings.rb @@ -46,5 +46,13 @@ def [](key) raise SettingNotFound.new("No setting found for #{key.inspect}") unless has_key?(key) super end + + def method_missing(key) + self[key.to_s] + rescue SettingNotFound + self[key.to_sym] + rescue SettingNotFound + super + end end end