diff --git a/lib/settingslogic.rb b/lib/settingslogic.rb index a99acaf..ed2d34c 100644 --- a/lib/settingslogic.rb +++ b/lib/settingslogic.rb @@ -113,6 +113,7 @@ def initialize(hash_or_file = self.class.source, section = nil) # Called for dynamically-defined keys, and also the first key deferenced at the top-level, if load! is not used. # Otherwise, create_accessors! (called by new) will have created actual methods for each key. def method_missing(name, *args, &block) + super if [:to_ary, :to_str].include?(name) # delegate to Hash key = name.to_s return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? key value = fetch(key) diff --git a/spec/settingslogic_spec.rb b/spec/settingslogic_spec.rb index 34e4798..33c6f3e 100644 --- a/spec/settingslogic_spec.rb +++ b/spec/settingslogic_spec.rb @@ -190,6 +190,11 @@ class NoSource < Settingslogic; end SettingsEmpty.keys.should eql([]) end + it "should delegate to_ary and to_str to Hash" do + [ Settings, ['a'] ].flatten.should == [Settings, 'a'] + [ Settings, ['a'] ].join.should == 'Settingsa' + end + # Put this test last or else call to .instance will load @instance, # masking bugs. it "should be a hash" do