Tsallaka zuwa abun ciki
Justice Tech School

Arrays

Arrays grow automatically. push, pop, shift, unshift, <<, first, last and slicing are common.

Example
a = [3, 1, 2]
a << 4
a.push(5)
a.unshift(0)
puts a.inspect, a.first, a.last(2).inspect, a[1..2].inspect, a.length

Result

[0, 3, 1, 2, 4, 5]
0
[4, 5]
[3, 1]
6

Exercise

Add to the end.

a  5

Quiz Test

What does shift remove?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.