I have a nested array with string values:
a = [["2000", "2004"], ["2005", "2007"]]
I am converting the value to integer like this:
int_val = []
a.each do |a|
int_val << a.map(&:to_i)
end
int_val #=> [[2000, 2004], [2005, 2007]]
Is there any short solution or one line code for this? [["2000", "2004"], ["2005", "2007"]].map(&:to_i) will not work.
[["2000", "2004"], ["2005", "2007"]].map{|row| row.map(&:to_i)}works...a.each do |a|– re-using an outer variable name (variable shadowing) can lead to confusion. Don't do that.