Forum: Ruby Extending Array instances

Posted by Charles Hixson (Guest)
on 2012-11-12 18:13
(Received via mailing list)
I'm trying to figure out a good way to extend an Array, when the items
may not be added in index order, and I don't know the final highest
index.  Does anyone have any suggestions?

What occurs to me is that I could double the length of the array
whenever I want to add more than one element by doing something like:
a    =    a    + Array.new(a.length)
Naturally, it would need to be a bit more complicated, as, e.g., I'd
need to ensure that the resulting array actually *would* hold the
proposed index.  Still, something only a little more complicated should
_work_, but is that the best approach?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.