Q:

Ruby add 31 days to date string within 2d array

I have a 2d array.    
 array = [["2014-01-12", "2014-01-12", "2014-01-12"],
          ["2012-08-26", "2012-10-18", "2012-08-31"],
          ["2013-04-09", "2013-05-22", "2013-07-01"]]

I need to add 31 days to the third value in each sub array (eg: "2014-01-12" & "2012-08-31" & "2012-07-01") 
I have considered something like:
changed_date = array.map { |due| ((Date.strptime(due[2], "%Y-%m-%d"))+ 31) }

But wanted to see what other ways there are of doing this...
Thanks!
EDIT:
I need the result to be an array of strings with with row.last having an additional 31 days. The resulting array should look like this:
array = ["2014-02-12", "2012-09-31", "2012-08-31"]

A:

You're doing it correct but you're changing your array form. Perhaps you should do
array.map{ |due| due[2] = (Date.strptime(due[2]) + 31).strftime("%Y-%m-%d"); due }

Or
array.each{ |due| due[2] = (Date.strptime(due[2]) + 31).strftime("%Y-%m-%d"); }

