solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Integer and float leading zero numeric coercion #123

Closed mduvall closed 11 years ago

mduvall commented 12 years ago

This may be myself not diving deep enough into the documentation - but is there a reason that non-significant type coercion for integers and floats does not coerce as Ruby does? (ie Virtus::Coercion::String.to_integer('010') returns '010' while '010'.to_i' returns 10 as a Fixnum in Ruby.)

This made it a little baffling in DataMapper where properties inherit Virtus coercion and Integers do not work as expected. Somebody else had also run into this issue: https://github.com/datamapper/dm-core/issues/228.

Should it be Virtus' responsibility to throw an exception or do the correct coercion? At the DataMapper layer this manifests itself as a silent failure... :-(

solnic commented 12 years ago

Next version will raise errors when it doesn't know how to coerce something. There's a discussion about it in issue #99 thread.

Re string numbers with leading zero, I guess we could follow ruby convention here.

mduvall commented 12 years ago

The string issue would be awesome!

dkubb commented 11 years ago

This issue is now resolved. The point @solnic mentions about raising errors when coercions are impossible is something separate. I'm going to mark this as resolved.