From fbc5edf0b5312005f8e9f79e4916e5f35b757647 Mon Sep 17 00:00:00 2001 From: Dmitry Kim Date: Fri, 14 Dec 2007 21:06:21 +0000 Subject: * (registry) fix the default value handling for non-existent registry files --- lib/rbot/registry.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'lib/rbot/registry.rb') diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb index cce2b5c8..cf27290a 100644 --- a/lib/rbot/registry.rb +++ b/lib/rbot/registry.rb @@ -191,27 +191,17 @@ class Bot debug ee end end - unless @default.nil? - begin - return Marshal.restore(@default) - rescue - return nil - end - else - return nil - end + return @default end end # lookup a key in the registry def [](key) - return nil unless File.exist?(@filename) + return @default unless File.exist?(@filename) if registry.has_key?(key) return restore(registry[key]) - elsif @default != nil - return restore(@default) else - return nil + return @default end end @@ -223,7 +213,7 @@ class Bot # set the default value for registry lookups, if the key sought is not # found, the default will be returned. The default default (har) is nil. def set_default (default) - @default = store(default) + @default = default end # just like Hash#each @@ -284,7 +274,7 @@ class Bot # delete a key from the registry def delete(key) - return nil unless File.exist?(@filename) + return @default unless File.exist?(@filename) return registry.delete(key) end -- cgit v1.2.3