Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

HWIA#to_hash should convert to normal Hash objects #267

Merged
merged 1 commit into from

2 participants

@radar

ActiveSupport::HashWithIndifferentAccess defines a to_hash method that converts to a vanilla Hash object, using String objects for the keys. Thor's version does not do this, and instead maintains it as the HWIA object instead.

This pull request fixes that problem, causing Thor's HWIA to now return a standard Ruby Hash object, just like AS does.

@wycats wycats merged commit 6f1b6b7 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 lib/thor/core_ext/hash_with_indifferent_access.rb
@@ -45,6 +45,11 @@ def merge!(other)
self
end
+ # Convert to a Hash with String keys.
+ def to_hash
+ Hash.new(default).merge!(self)
+ end
+
protected
def convert_key(key)
View
5 spec/core_ext/hash_with_indifferent_access_spec.rb
@@ -40,4 +40,9 @@
expect(other[:force]).to eq(false)
expect(other[:baz]).to eq("boom")
end
+
+ it "converts to a traditional hash" do
+ expect(@hash.to_hash.class).to eq(Hash)
+ expect(@hash).to eq({ 'foo' => 'bar', 'baz' => 'bee', 'force' => true })
+ end
end
Something went wrong with that request. Please try again.