Unit::ConversionError
Inherits Unit::UnitError < Exception < Reference < Object
Exception raised when a conversion between units fails. This typically happens when attempting to convert between incompatible measurement types (e.g., weight to length).
Example:
begin
weight = Weight.new(10, :kg)
length = Length.new(5, :m)
# This would raise ConversionError:
# weight + length
rescue ex : Unit::ConversionError
puts ex.message # => "Cannot convert from Weight to Length: Incompatible measurement types"
end
Constructors
new(from_unit, to_unit, reason = nil)
Alternative constructor that accepts unit types directly
Class methods
incompatible_types(from_type : T.class, to_type : U.class) forall T, U
Factory method for incompatible type conversions
Instance methods
from_unit
Sourcereason
Sourceto_unit
Source