Class: Complex

Inherits:
Numeric show all
Defined in:
lib/ruby_units/complex.rb

Instance Method Summary collapse

Instance Method Details

#to_unit(other = nil) ⇒ Object Also known as: unit

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
# File 'lib/ruby_units/complex.rb', line 2

def to_unit(other = nil)
  real_unit = self.real.to_unit
  image_unit = self.imaginary.to_unit
  raise ArgumentError, 'Units on real and imaginary parts are incompatible' unless real_unit =~ image_unit 
  final_unit = (real_unit.units.empty? ? image_unit.units : real_unit.units).to_unit
  final_unit * Complex(real_unit.to(final_unit).scalar, image_unit.to(final_unit).scalar)
end