Skip to content
Browse files

properly reimplement to_hash

  • Loading branch information...
1 parent 6be535a commit 13b865a5c9824552ba72c649480bd748b0d98c2e @cmer committed Oct 31, 2012
Showing with 15 additions and 2 deletions.
  1. +5 −0 lib/settingslogic.rb
  2. +10 −2 spec/settingslogic_spec.rb
View
5 lib/settingslogic.rb
@@ -143,6 +143,11 @@ def []=(key,val)
create_accessor_for(key, val)
end
+ # Returns an instance of a Hash object
+ def to_hash
+ Hash[self]
@PikachuEXE
PikachuEXE added a note Nov 16, 2012

I prefer writing Hash.new(self) though :p

Edit: Hash.new(self) does not work >_<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ end
+
# This handles naming collisions with Sinatra/Vlad/Capistrano. Since these use a set()
# helper that defines methods in Object, ANY method_missing ANYWHERE picks up the Vlad/Sinatra
# settings! So settings.deploy_to title actually calls Object.deploy_to (from set :deploy_to, "host"),
View
12 spec/settingslogic_spec.rb
@@ -162,5 +162,13 @@ class NoSource < Settingslogic; end
it "should be a hash" do
Settings.send(:instance).should be_is_a(Hash)
end
-
-end
+
+ describe "#to_hash" do
+ it "should return a new instance of a Hash object" do
+ Settings.to_hash.should be_kind_of(Hash)
+ Settings.to_hash.class.name.should == "Hash"
+ Settings.to_hash.object_id.should_not == Settings.object_id
+ end
+ end
+
+end

0 comments on commit 13b865a

Please sign in to comment.
Something went wrong with that request. Please try again.