ruby - Iterate over array whilst amending the same array -
The following array repetition works fine
data = [17, 22, 12, 24] Data. Items | "Number: # {item}" end
I would like to insert a new array in the same array instead of puts
I fail to believe that it is making an infinite loop.
Data = [17, 22, 12, 24] Data. Items | Data & lt; & Lt; I tried to do
instead of
If you want to add new items to the array, do so:
data = [17, 22, 12, 24] data.cunk data data.collect {| i | "number: # {i}"} # data => [17, 22 If you just want to change with the new items, 12, 24, "number: 17", "number: 22", "number: 12", "number: 24"]
Data content:
data = date .collect {| i | "number: # {i}"}
Comments
Post a Comment