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 Hashie::Dash Defaults #63

Merged
merged 2 commits into from Feb 12, 2013
Merged

Fix Hashie::Dash Defaults #63

merged 2 commits into from Feb 12, 2013

Conversation

ohrite
Copy link
Contributor

@ohrite ohrite commented Nov 4, 2012

Previously, a Hashie::Dash's property's :default value was used by all instantiations.
This change calls .dup on all non-Numeric default values during instantiation, rescuing from TypeError.

@ohrite
Copy link
Contributor Author

ohrite commented Nov 4, 2012

This also addresses #53

else
begin
value.dup
rescue TypeError
Copy link
Contributor

Choose a reason for hiding this comment

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

What objects throw TypeError when they're duped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the Rails docs, the non-duplicable objects are: nil, false, true, symbols, numbers, class objects and module objects.

@jch
Copy link
Contributor

jch commented Dec 12, 2012

👍 looks good to me.

@ohrite
Copy link
Contributor Author

ohrite commented Dec 14, 2012

I've had a change of heart over the last few weeks over handling the Numeric case. If conciseness is desired, doing the minimal version is probably just as good:

self[prop] = begin
  value.dup
rescue TypeError
  value
end

@jch
Copy link
Contributor

jch commented Feb 12, 2013

Thanks @ohrite for the pull! I'm helping clean up issues and pulls and got commit access. If you don't mind, could you update your pull to use the concise version you described in the comment above?

ohrite and others added 2 commits February 12, 2013 14:22
Previously, a Hashie::Dash's property's :default value was used by all instantiations.
This change calls .dup on all non-Numeric default values during instantiation, rescuing from TypeError.
@ohrite
Copy link
Contributor Author

ohrite commented Feb 12, 2013

@jch updated to the concise version and ready to rock!

jch added a commit that referenced this pull request Feb 12, 2013
@jch jch merged commit 58ebe33 into hashie:master Feb 12, 2013
@jch
Copy link
Contributor

jch commented Feb 12, 2013

Thanks! 🍻

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

Successfully merging this pull request may close these issues.

None yet

2 participants