Arrays in Ruby are very similar to those in other dynamic programming languages. It’s all very standard and the documentation has loads of examples anyway, so I’ll go through only the most basic and obvious to get started.
Construction
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Accessing elements and array info
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Adding to the array
1 2 3 4 5 6 7 8 9 10 |
|
Removing from Array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Print vs Puts
Both these functions can be used to output text. To put it simply, puts adds a newline character to the end of each argument and outputs nil as an invisible character rather than a String. Refer to the link at the bottom for more discussion.
1 2 3 4 5 6 7 |
|