Shopify / measured

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

Numerical comparison against all types of zeros should be permitted #12

Closed cyprusad closed 9 years ago

cyprusad commented 9 years ago

@Shopify/shipping

Previously, comparing a Measured::Measurable against any scalar raised an ArgumentError since it expects all arguments being compared to be of the same class. This prevented us from comparing against 0 which is a pretty good UX for this gem. Comparison with zeros of BigDecimal (i.e BigDecimal.new(0)) and Float (i.e 0.0) work as expected.

Comparing Measured::Measurable objects against other non-zero scalars still raises an error just like before.

Example:

x = Measured::Length(2, :m)
x > 0  ## evaluates to true
x < 0.0 ## evaluates to false
x == BigDecimal.new(0) ## also false

x == 2 ## ArgumentError
trishume commented 9 years ago

:+1:

garethson commented 9 years ago

:ship:

kmcphillips commented 9 years ago

Looks good!

kmcphillips commented 9 years ago

Can you bump the minor version and update a couple lines in the README?

cyprusad commented 9 years ago

@kmcphillips done