Shopify / measured

Encapsulate measurements and their units in Ruby and Ruby on Rails.
MIT License
337 stars 28 forks source link

Add a util module that gives named functions on Integer, Float, and BigDecimal #39

Open thegedge opened 7 years ago

thegedge commented 7 years ago

For example, 1.metres.

kmcphillips commented 7 years ago

Few points about this. If we decide we want to:

One of the major reasons we built rather than used was that so many existing tools overrode core types and added methods globally. That's dangerous behaviour, unless you opt into wanting it.

thegedge commented 7 years ago

Yep, I really should have mentioned that I intended for this to be opt-in, similar to bigdecimal/util adding to_d to a bunch of core types. Thanks for calling that out!

thegedge commented 7 years ago

@kmcphillips what do you think of having Measured.build(add_numeric_extensions: true) to support this? Or do you think it would be better to have something like require 'measured/numeric_extensions' that wraps Measured.build? I'm thinking something like the latter, because it would be the only way for us to have extensions for Length / Weight.

kmcphillips commented 7 years ago

This doesn't need to be part of the DSL. I'd much rather it be an optional, not included by default, extension that you can require.