Class: Complex

Inherits:
Object show all
Defined in:
lib/backports/1.9.2/complex/to_r.rb,
lib/backports/2.7.0/complex/comparison.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/backports/2.7.0/complex/comparison.rb', line 3

def <=>(other)
  return nil unless imaginary.zero?

  if other.is_a?(Complex)
    other.imaginary.zero? ? real <=> other.real : nil
  else
    real <=> other
  end
end

#to_rObject

Raises:

  • (RangeError)


4
5
6
7
# File 'lib/backports/1.9.2/complex/to_r.rb', line 4

def to_r
  raise RangeError, "Can't convert #{self} into Rational" unless imag.eql?(0)
  real.to_r
end