Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/complex.rb

Overview

Numeric is a built-in class on which Fixnum, Bignum, etc., are based. Here some methods are added so that all number types can be treated to some extent as Complex numbers.

Direct Known Subclasses

Complex

Instance Method Summary collapse

Instance Method Details

#argObject Also known as: angle

See Complex#arg.



60
61
62
63
64
65
66
67
68
# File 'lib/complex.rb', line 60

def arg
  if self > 0 || (self == 0 && self.to_s != '-0.0') # This string comparison stuff is gross. Better way?
    return 0
  elsif self.to_f.nan?
    return self
  else
    return Math::PI
  end
end

#conjugateObject Also known as: conj

See Complex#conjugate (short answer: returns self).



81
82
83
# File 'lib/complex.rb', line 81

def conjugate
  self
end

#imObject

Returns a Complex number (0,self).



38
39
40
# File 'lib/complex.rb', line 38

def im
  Complex(0, self)
end

#imageObject Also known as: imag

The imaginary part of a complex number, i.e. 0.



52
53
54
# File 'lib/complex.rb', line 52

def image
  0
end

#polarObject

See Complex#polar.



74
75
76
# File 'lib/complex.rb', line 74

def polar
  return abs, arg
end

#realObject

The real part of a complex number, i.e. self.



45
46
47
# File 'lib/complex.rb', line 45

def real
  self
end