Skip to content

Instantly share code, notes, and snippets.

@acook
Created December 11, 2012 07:36
Show Gist options
  • Save acook/4256609 to your computer and use it in GitHub Desktop.
Save acook/4256609 to your computer and use it in GitHub Desktop.
Invert an Array
def invert original
result = Marshal.load Marshal.dump(original)
original.each_with_index do |row, r_index|
row.each_with_index do |column, c_index|
result[c_index][r_index] = column
end
end
result
end
array = [[1,2],[3,4]]
invert array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment