From 45eb5bfe4ea1a3f3368a5daba146d0d1a228f04b Mon Sep 17 00:00:00 2001 From: krissi Date: Thu, 17 Jan 2013 15:05:25 +0100 Subject: [PATCH 1/2] added method_missing to access the hash via hsh.key --- lib/settings.rb | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From df6a12623d70b6e7709aee7751af4f2d6139229a Mon Sep 17 00:00:00 2001 From: krissi Date: Thu, 17 Jan 2013 15:08:54 +0100 Subject: [PATCH 2/2] updated readme --- README.md | 1 + 1 file changed, 1 insertion(+) 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"])