In Ruby, you can declare an array using square brackets or the Array.new method.
In this example,
numbers
using square brackets and initialize it with some values.numbers = [1, 2, 3, 4, 5]
puts numbers
1 2 3 4 5
In this example,
names
using the Array.new
method and initialize it with some strings.names = Array.new(3, 'Alice')
puts names
Alice Alice Alice
In this tutorial, we learned How to Declare an Array in Ruby language with well detailed examples.