Skip to content

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

instance method

Integer#magnitude

int.magnitude → integer

Alias of #abs

Returns the absolute value of int.

Example
(-12345).abs   #=> 12345
-12345.abs     #=> 12345
12345.abs      #=> 12345

Integer#magnitude is an alias for Integer#abs.

See also #abs #lcm #modulo #integer? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0