Commit a905605bf5cbed8129fb4ad99d2d4a651ae72103
Exists in
master
Merge pull request #44 from cmer/master
Properly implement to_hash
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
lib/settingslogic.rb
... | ... | @@ -143,6 +143,11 @@ class Settingslogic < Hash |
143 | 143 | create_accessor_for(key, val) |
144 | 144 | end |
145 | 145 | |
146 | + # Returns an instance of a Hash object | |
147 | + def to_hash | |
148 | + Hash[self] | |
149 | + end | |
150 | + | |
146 | 151 | # This handles naming collisions with Sinatra/Vlad/Capistrano. Since these use a set() |
147 | 152 | # helper that defines methods in Object, ANY method_missing ANYWHERE picks up the Vlad/Sinatra |
148 | 153 | # settings! So settings.deploy_to title actually calls Object.deploy_to (from set :deploy_to, "host"), | ... | ... |
spec/settingslogic_spec.rb
... | ... | @@ -162,5 +162,13 @@ describe "Settingslogic" do |
162 | 162 | it "should be a hash" do |
163 | 163 | Settings.send(:instance).should be_is_a(Hash) |
164 | 164 | 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 | |
167 | 175 | \ No newline at end of file | ... | ... |