In this blog, you’ll see how to use Array in Ruby.
You can define and use the array like the below.
cats = ['Nabi', 'Mini', 'Kitty'] puts cat # Navi
Like other languages, the Ruby array index is also started
Below is the easiest way to define the array.
cats = ['Nabi', 'Mini', 'Kitty']
But, you can also use
Array.new to make an array.
cats = Array.new # 
If you define with no parameter like above, the 0 element array is created.
cats = Array.new(2) # [nil, nil]
If you set one parameter like above, the array is created with the size of the number, and filled
cats = Array.new(3, 1) # [1, 1, 1]
If you define the array as above, the array has
3 elements filled
You can use
length to get the array size.
cats = ['Nabi', 'Mini', 'Kitty'] cats.size # 3
You can use
length as below.
cats = ['Nabi', 'Mini', 'Kitty'] cats.length # 3
You can use the
clear function to delete all values in the array.
cats = ['Nabi', 'Mini', 'Kitty'] cats.clear # 
Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!
Dekucreated the applications with Flutter.
If you have interested, please try to download them for free.