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

Numeric#abs

abs → numeric

Returns the absolute value of self.

Example
12.abs        #=> 12
(-34.56).abs  #=> 34.56
-34.56.abs    #=> 34.56

Numeric#magnitude is an alias for Numeric#abs.

See also #<=> #abs2 #-@ #angle also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0