Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix HashWithIndifferentAccess#to_hash behaviour #10266

Merged
merged 1 commit into from May 14, 2013

Conversation

vipulnsward
Copy link
Member

Currently HashWithIndifferentAccess#to_hash ,returns a hash containing HashWithIndifferentAccess within for a nested hash, eg

if
{:a => {:b => {:c => '3'}}} is a HashWithIndifferentAccess
then #to_hash returns

{:a => {:b => {:c => '3'}}}
where {:b => {:c => '3'}} is a HashWithIndifferentAccess object, while the whole object itself is a Hash

@@ -229,7 +229,11 @@ def to_options!; self end

# Convert to a regular hash with string keys.
def to_hash
Hash.new(default).merge!(self)
_new_hash= {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please suggest on a faster way to copy to a new hash if any.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the best one

@rafaelfranca
Copy link
Member

Could you add a test case?

@vipulnsward
Copy link
Member Author

adding

@vipulnsward
Copy link
Member Author

added

@vipulnsward
Copy link
Member Author

@rafaelfranca anything else, I should update?

@vipulnsward
Copy link
Member Author

@rafaelfranca 1 month ping. Anything else this needs to handle?

rafaelfranca added a commit that referenced this pull request May 14, 2013
fix HashWithIndifferentAccess#to_hash behaviour
@rafaelfranca rafaelfranca merged commit c718256 into rails:master May 14, 2013
@egilburg
Copy link
Contributor

Hmm, seems a bit counterintuitive to me - the method isn't called e.g. deep_to_hash; usually to_* methods don't mutate nested objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants