- Published
- Author
- Ayush
.abs method in Ruby is used to return the absolute value of a number. The absolute value of a number is its distance from zero, regardless of direction. In other words, it's the number without its sign.Here's an example:
Ruby
num = -10
puts num.abs # Outputs: 10In this example,
num.abs returns 10 because the absolute value of -10 is 10.Similarly, for a positive number:
Ruby
num = 10
puts num.abs # Outputs: 10