in the simplest case
depth = Proc.new do |array| depth = 1 while Array === array.first do array = array.first depth += 1 end depth end array = [[[1,2],[2,3]],[[3,4],[5]]] depth.call(array)
Or this tiny recursive method
def depth(array, depth=1) array = array.send(:first) Array === array ? depth(array, depth+1) : depth end array = [[[1,2],[2,3]],[[3,4],[5]]] depth(array)
fl00r source share