Skip to content

Instantly share code, notes, and snippets.

@photomattmills
Created December 18, 2010 00:16
Show Gist options
  • Save photomattmills/745953 to your computer and use it in GitHub Desktop.
Save photomattmills/745953 to your computer and use it in GitHub Desktop.
This method will go through all the children in a multidimensional array.
array = [:first,:first,[:second,:second,[:third,:third,[:fourth,:fourth]]]]
def walk(array)
if array.class == Array
array.each do |item|
if item.class == Array
item.each { |i| walk(i) }
else
puts item
end
end
else
puts array
end
end
walk(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment