-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
The automatic canceling of units might be an area for improvements.
I consciously did not make all cancelable units cancel automatically as there are cases where we want to preserve the units. For example, and quantity of x kilograms per kilogram of y is technically dimensionless (kg/kg - they cancel) but we might want to retain the context of it being "some mass per mass of something else".
Quantify currently support two systems for handling this:
- All units have an #acts_as_equivalent_unit flag. If a compound unit is derived from an operation a check is made to see if the unit is equivalent to another non-compound unit. If so, and if this non-compound unit has the #acts_as_equivalent_unit flag set to true, then the compound unit is replaced by the non-compound unit. The flag is basically say that "this unit should override any compound representations of the same thing". By default, all base units are configured to do this as well as some important units like joule, newton, and watt. So kg * m^2 / s^2 reduces to 'joule' and kg * L / kg reduces to L. This is not quite the same as cancelling, but rather replacing with an equivalent unit. It can give the impression of cancelling in some cases.
- The quantity and compound unit classes have methods for explicitly cancelling units. These methods take the units to cancel by as arguments. This represent a manual cancelling of units. I saw this as the best approach - do not cancel by default, but enable cancelling when the user chooses to.
The second approach is useful, but requires an extra method call which seems a bit much at times. Perhaps a global switch for declaring that all operations should cancel units would provide the right compromise between ease and control?
Metadata
Metadata
Assignees
Labels
No labels