Should I use an Array?

So, I'm still trying to dive into ruby and I thought of an idea;

Using 3 pictures (Head, Body, Tail) I would create a line of pictures that would move the head forward and extend the body, like so;

/T/B/B/B/H

The amount of bodies would change depending on what length I wanted, right.

So my train of thought was create an Array with the size of a parameter variable I.E; 5 and then use a for each loop to move/add more pictures. The problem is I can't seem to set the Array size passed 1 initially, so I'm wondering if I'm even on the right thought pattern?
If I understand correctly, you want to increase the size of your array.

So when you have an array like this:
Code:
arr = [ T, B, B, B, H ]

You can do:
Code:
arr.push(X)

or
Code:
arr << X

to get:
[ T, B, B, B, H, X ]

Refer to the Ruby documentation for more details and features: http://ruby-doc.org/core-2.5.0/Array.html


PS: I wouldn't recommend putting Head, Tail, and Body in your array.
You already know the first element will always be Tail, the last one will always be Head, and in between is always Body.

Instead, put coordinates in the array. That way, you know where each segment of your snake's body is (I assume you're trying to make a Snake-clone).
In your loop you can use an "if" to draw a tail if it's the first element, and a head if it's the last.

To remove the first element, you can use:
Code:
arr.shift
I'd approach using a completely different class
Code:
class Snake
  def initialize
    @head = ''
    @body = []
    @tail = ''
  end
end
Using a different class, you can even mimicking an array but with different operations

Original thread: https://forums.rpgmakerweb.com/threads/should-i-use-an-array.92500/