Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Complex.rectangular
(::Numeric, ?::Numeric) -> ::Complex
Complex.rect(real, imag = 0) → complex
complex.c
View on GitHub ↗
static VALUE
nucomp_s_new(int argc, VALUE *argv, VALUE klass)
{
VALUE real, imag;
switch (rb_scan_args(argc, argv, "11", &real, &imag)) {
case 1:
real = nucomp_real_check(real);
imag = ZERO;
break;
default:
real = nucomp_real_check(real);
imag = nucomp_real_check(imag);
break;
}
return nucomp_s_new_internal(klass, real, imag);
}
Returns a new Complex object formed from the arguments, each of which must be an instance of Numeric, or an instance of one of its subclasses: Complex, Float, Integer, Rational; see Rectangular Coordinates:
Example
Complex.rect(3) # => (3+0i) Complex.rect(3, Math::PI) # => (3+3.141592653589793i) Complex.rect(-3, -Math::PI) # => (-3-3.141592653589793i)
Complex.rectangular is an alias for Complex.rect.