for example, I have an array which is structured as follow:
my_array = [["..\\..\\..\\Source\\file1.c"], ["..\\..\\..\\Source\\file2.c"]]
This array is produced by this code:
File.open(file_name) do |f|
f.each_line {|line|
if line =~ /<ClCompile Include="..\\/
my_array << line.scan(/".*.c"/)
end
}
end
Later in the code I'm working on the array:
my_array .each {|n| f.puts n.gsub(/\\/,"//")}
As you can see, would like to replace all the backslashes with forward slashes on the elements within the array. The elements presents paths to source files. On the end I will output these paths within an other file.
I get this error:
undefined method `gsub' for [["..\\..\\..\\Source\\file1.c"], ["..\\..\\..\\Source\\file2.c"]]:Array (NoMethodError)
Any idea?
my_array.flatten.eachinstead (you have a multi-dimensional Array, an Array of Arrays, andflattenwill make it a one-dimensional Array)