Commit 13b865a5c9824552ba72c649480bd748b0d98c2e
1 parent
6be535aa
Exists in
master
properly reimplement 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,6 +143,11 @@ class Settingslogic < Hash | ||
143 | create_accessor_for(key, val) | 143 | create_accessor_for(key, val) |
144 | end | 144 | end |
145 | 145 | ||
146 | + # Returns an instance of a Hash object | ||
147 | + def to_hash | ||
148 | + Hash[self] | ||
149 | + end | ||
150 | + | ||
146 | # This handles naming collisions with Sinatra/Vlad/Capistrano. Since these use a set() | 151 | # This handles naming collisions with Sinatra/Vlad/Capistrano. Since these use a set() |
147 | # helper that defines methods in Object, ANY method_missing ANYWHERE picks up the Vlad/Sinatra | 152 | # helper that defines methods in Object, ANY method_missing ANYWHERE picks up the Vlad/Sinatra |
148 | # settings! So settings.deploy_to title actually calls Object.deploy_to (from set :deploy_to, "host"), | 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,5 +162,13 @@ describe "Settingslogic" do | ||
162 | it "should be a hash" do | 162 | it "should be a hash" do |
163 | Settings.send(:instance).should be_is_a(Hash) | 163 | Settings.send(:instance).should be_is_a(Hash) |
164 | end | 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 | \ No newline at end of file | 175 | \ No newline at end of file |