To sort an array in ascending order in Ruby, you can use the `sort` method for both arrays of integers and arrays of strings.
In this example,
numbers
.sort
method to sort the array of integers in ascending order.numbers = [5, 2, 8, 1, 9]
numbers.sort!
puts numbers
1 2 5 8 9
In this example,
words
.sort
method to sort the array of strings in ascending order.words = ["apple", "banana", "cherry", "date"]
words.sort!
puts words
apple banana cherry date
In this tutorial, we learned How to Sort an Array in Ascending Order in Ruby language with well detailed examples.