Skip to content

Commit 13b865a

Browse files
committed
properly reimplement to_hash
1 parent 6be535a commit 13b865a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/settingslogic.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ def []=(key,val)
143143
create_accessor_for(key, val)
144144
end
145145

146+
# Returns an instance of a Hash object
147+
def to_hash
148+
Hash[self]
149+
end
150+
146151
# This handles naming collisions with Sinatra/Vlad/Capistrano. Since these use a set()
147152
# helper that defines methods in Object, ANY method_missing ANYWHERE picks up the Vlad/Sinatra
148153
# settings! So settings.deploy_to title actually calls Object.deploy_to (from set :deploy_to, "host"),

spec/settingslogic_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,13 @@ class NoSource < Settingslogic; end
162162
it "should be a hash" do
163163
Settings.send(:instance).should be_is_a(Hash)
164164
end
165-
166-
end
165+
166+
describe "#to_hash" do
167+
it "should return a new instance of a Hash object" do
168+
Settings.to_hash.should be_kind_of(Hash)
169+
Settings.to_hash.class.name.should == "Hash"
170+
Settings.to_hash.object_id.should_not == Settings.object_id
171+
end
172+
end
173+
174+
end

0 commit comments

Comments
 (0)