Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Complex#imaginary

imag -> numeric

Returns the imaginary value for self:

Example
Complex(7).imaginary      #=> 0
Complex(9, -4).imaginary  #=> -4

If self was created with polar coordinates, the returned value is computed, and may be inexact:

Example
Complex.polar(1, Math::PI/4).imag # => 0.7071067811865476 # Square root of 2.
See also #imag #infinite? #hash #inspect also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0