Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Complex#inspect

cmp.inspect → string

Returns the value as a string for inspection.

Example
Complex(2).inspect                       #=> "(2+0i)"
Complex('-8/6').inspect                  #=> "((-4/3)+0i)"
Complex('1/2i').inspect                  #=> "(0+(1/2)*i)"
Complex(0, Float::INFINITY).inspect      #=> "(0+Infinity*i)"
Complex(Float::NAN, Float::NAN).inspect  #=> "(NaN+NaN*i)"
See also #infinite? #magnitude #imaginary #numerator also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0