Method: RubyUnits::Unit#to_i

Defined in:
lib/ruby_units/unit.rb

#to_iInteger Also known as: to_int

if unitless, returns an int, otherwise raises an error

Returns:

  • (Integer)

Raises:

  • (RuntimeError)

    when not unitless



1245
1246
1247
1248
1249
# File 'lib/ruby_units/unit.rb', line 1245

def to_i
  return @scalar.to_int if unitless?

  raise "Cannot convert '#{self}' to Integer unless unitless.  Use Unit#scalar"
end