Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Complex#inspect
() -> ::String
inspect → string
complex.c
View on GitHub ↗
static VALUE
nucomp_inspect(VALUE self)
{
VALUE s;
s = rb_usascii_str_new2("(");
f_format(self, s, rb_inspect);
rb_str_cat2(s, ")");
return s;
}
Returns a string representation of self:
Example
Complex.rect(2).inspect # => "(2+0i)" Complex.rect(-8, 6).inspect # => "(-8+6i)" Complex.rect(0, Rational(1, 2)).inspect # => "(0+(1/2)*i)" Complex.rect(0, Float::INFINITY).inspect # => "(0+Infinity*i)" Complex.rect(Float::NAN, Float::NAN).inspect # => "(NaN+NaN*i)"