To take the absolute value of a number in Ruby, you can use the abs method that is available on Numeric objects. Here's an example:
main.rb68 chars4 lines
In this example, we're creating a variable num with a value of -10. We then call the abs method on num to get its absolute value, which is assigned to the variable absolute_value. Finally, we use puts to print out the value of absolute_value, which is 10.
gistlibby LogSnag