Method: Sass::Script::Number#coerce

Defined in:
lib/sass/script/number.rb

#coerce(num_units, den_units) ⇒ Number

Returns this number converted to other units. The conversion takes into account the relationship between e.g. mm and cm, as well as between e.g. in and cm.

If this number has no units, it will simply return itself with the given units.

An incompatible coercion, e.g. between px and cm, will raise an error.

Parameters:

Returns:

  • (Number)

    The number with the new units

Raises:



321
322
323
324
325
326
327
328
# File 'lib/sass/script/number.rb', line 321

def coerce(num_units, den_units)
  Number.new(if unitless?
               self.value
             else
               self.value * coercion_factor(@numerator_units, num_units) /
                 coercion_factor(@denominator_units, den_units)
             end, num_units, den_units)
end