Adding to an Array

I’ve been looking at the array stuff in the Noobkit, but I can’t seem
to find how to insert another entry in the array… Pretty much, I’m
going to be iterating through stuff and catching some things and adding
them to an array. I want to always add to the end of the array… In
stuff I’ve seen, you must define an index.

Any suggestions?


  • Jeff

@a =
@a.push “item1”
@a << “item2”
@a.join(",") => “item1”, “item2”

that’s not correct. This is what it does:

a =
=> []

a.push “item1”
=> [“item1”]

a << “item2”
=> [“item1”, “item2”]

=> “item1,item2”

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #4 coming soon!

On 15/04/2008, at 12:02 PM, Nathan E. wrote:

@a =
@a.push “item1”
@a << “item2”
@a.join(",") => “item1”, “item2”

Posted via


Right, my bad.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs