dimanche 12 février 2017

Ruby Array default value?

Vote count: 0

I have an array:

row = ["foo", "tom", "fluffy",1, 4]

I would like to append some value at index = 7. This is easy and ruby fills in the missing indexes with nil:

row[7] = "some value"
=> ["foo", "tom", "fluffy", 1, 4, nil, nil, "some value"]

I would like to have control over what is filled in place of the nil

specifically I would like column_N where N is the index. Something like:

=> ["foo", "tom", "fluffy", 1, 4, "column_5", "column_6", "some value"]

asked 12 secs ago

Let's block ads! (Why?)



Ruby Array default value?

Aucun commentaire:

Enregistrer un commentaire