Ruby: at given an index in a 2d array, replace the first element in the subarray at that index -


I have a 2D array that looks:

  array = [["apple" I want to change some strings in the code like "," [orange ", 12], [" peach ", 15], [" lemon ", 7]]  / code>, (except the second code in  array  unchanged) with the help of another 2d array is included in the string that I want to use as a replacement and in other case there is an index. Want to            

code> etc. In the first position of the array on index 1, put the blanket . Viewing the output

  Output Anyone can help me: ["Apple", 10], ["blanket", 12], ["Peach", 15], ["Footwear ", 7]]   

this?

should do the following :

  replacements.each {| r | array [r [1]] [0] = r [0]}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -