Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Array#flatten on an array containing a Settingslogic object #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/settingslogic.rb
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spec/settingslogic_spec.rb
Expand Up @@ -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
Expand Down