Question: I have arrays like this:

```
myArr = [a,b,c,d,e,f,g]
myArr = [a]
myArr = [a,b,c]

```

**How can I break up the arrays such that:**

Variable `first_portion` has the **first 3 items** and `rest_portion` **has all remaining ones**?

If an array has 3 or less items, I'd like rest\_portion to contain nil so that I can check for it in logic.

**Any advise?**

Answer: 
You can use a range for the array index to accomplish this easily:

```
first_portion = myArr[0..2]
rest_portion = myArr[3..-1]

```

If the range partially overlaps the range, you'll get an array with only as many items as are available. If the range has no overlap with the array, you'll get nil.

```
[a,b,c,d,e,f,g][0..2]
#=> [a, b, c]
[a,b,c,d,e,f,g][3..-1]
#=> [d,e,f,g]

[a][0..2]
#=> [a]
[a][3..-1]
#=> nil

```
Look at [Array#shift](http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-shift)

```
>>  myArr = [1,2,3,4,5,6]
=> [1, 2, 3, 4, 5, 6]
>> firstPart = myArr.shift(3)
=> [1, 2, 3]
>> firstPart
=> [1, 2, 3]
>> myArr
=> [4, 5, 6]

```