class Complex

Public Instance Methods

<=>(other) click to toggle source
# File lib/backports/2.7.0/complex/comparision.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_r() click to toggle source
# 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