Shopify / measured

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

Convert as required when doing comparison between different units #11

Closed kmcphillips closed 9 years ago

kmcphillips commented 9 years ago

@Shopify/shipping

Changes implementation of comparison operators (==, .eql?, and <=>) to do the conversion between units. Does this only as needed.

Update the convert_to operator to exit early and return the measurement unchanged if the conversion is to the unit it is already in.

Example, this was false but is now true:

> Measured::Length(1000, :cm) == Measured::Length(1, :m)
true
kmcphillips commented 9 years ago

Bumps to version 0.0.6