The magnitude() is an inbuilt method in Ruby returns the magnitude of a number.
Syntax: num.magnitude
Parameters: The function needs the number whose magnitude is to be returned.
Return Value: It returns the magnitude of a number.
Example 1:
Ruby
# Ruby program for magnitude() method in Numeric # Initialize a number num = - 19 # Prints magnitude of num puts num.magnitude() |
Output:
19
Example 2:
Ruby
# Ruby program for magnitude() method in Numeric # Initialize a number num = 100 # Prints magnitude of num puts num.magnitude() |
Output:
100