Mar 21

Ruby Arrays. Hashes and Ranges (Part 3)

Category: Basics, Sample Code

Array’s can be created ahead of time in say a initialization routine where you initialize all the array’s you might need in a group or block of code so you don’t have to worry about that later. To do so, you simply use the “.new” method (Spaghetti_Sauce = Array.new), which gives you an empty array named Spaghetti_Sauce. To assign values to the empty array, you simply assign values to it as with the similar example:

Spaghetti_sauce[0] = “ground pork”
Spaghetti_sauce[1] = “ground beef”
Spaghetti_sauce[2] = “tomato sauce”

More on Arrays in the next post.

Comments are off for this post

Comments are closed.