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

Coercion: Cast with kernel methods instead of to_* methods? #263

Open
maxlinc opened this issue Jan 9, 2015 · 1 comment
Open

Coercion: Cast with kernel methods instead of to_* methods? #263

maxlinc opened this issue Jan 9, 2015 · 1 comment

Comments

@maxlinc
Copy link
Contributor

maxlinc commented Jan 9, 2015

Currently Hashie is coercing to core types with conversion methods:

type method
Integer #to_i
Float #to_f
Complex #to_c
Rational #to_r
String #to_s
Symbol #to_sym

Some of these methods are pretty lenient and may produce undesirable results. There are Kernel methods to cast types that are more strict, like Float:

"abcd".to_f # => 0.0
Float("abcd") # ArgumentError: invalid value for Float(): "abcd"

Would it be better if Hashie used the stricter approach by default?

@dblock
Copy link
Member

dblock commented Jan 9, 2015

Yes, I think we can all agree that it would be better, however this would introduce some interesting behavior from the user POV. I wonder whether we want to support both, configure it globally, deprecate? Either way I think you should try to PR the replacement one, lets see what breaks in existing specs alone.

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

No branches or pull requests

2 participants