ALL ABOUT 
ARRAYS

NOTEBOOK


presented by Anna Mendoza

L.A. Ruby Montly Meetups




what are  
ARRAYS?



Arrays are...

  An Array is a sequential collection of items in 

which each item can be indexed.   

  In Ruby, (unlike many other languages) a single Array 

can hold items of  mixed data types such as strings, 

integers and floats or even a method-call 

which returns some value:  

 
a1 = [1,'two', 3.0, array_length(a0)]



  The first item in an array has the index 0, 
which means that the final item has an index equal
to the total number of items in the array minus 1.
Given the following array, this is how
to obtain the values of the first and last items:

a1[0] # returns 1st item (at index 0) a1[3] # returns 4th item (at index 3) 


 

Creating Arrays


In common with many other programming languages, 

Ruby uses square brackets to delimit an array. 

You can easily create an array, fill it with some 

comma-delimited values and assign it to a variable:


arr = ['one','two','three','four']




Arrays are...

You can reference an item in an array by placing
its index between square brackets.
If the index is invalid, nil is returned:

 
arr = ['a', 'b', 'c']
puts(arr[0]) # shows a‟ puts(arr[1]) # shows b‟ puts(arr[2]) # shows c‟
puts(arr[3]) # nil




And that's what ARRAYS are!









THANK YOU!!

ANNA ( @CURVECOMM ) 

Present this....



All About Arrays

By Anna Mendoza

All About Arrays

Observing the culture of Silicon Beach and documenting it.

  • 880