def dependencies_array(leaf, processed = {})
      return processed[leaf] if processed[leaf]

      deps_array = []
      processed[leaf] = deps_array

      leaf.each do |pack, versions|
        a = []
        versions.each do |version, deps|
          perms = []
          sub_perms = dependencies_array(deps, processed)
          if sub_perms == []
            perms += [version]
          else
            sub_perms[0].each do |perm|
              perms << [version] + [perm].flatten
            end
          end
          a += perms
        end
        deps_array << a
      end

      deps_array
    end
def dependencies_array(leaf, processed = {})
      return processed[leaf] if processed[leaf]

      deps_array = []
      processed[leaf] = deps_array

      leaf.each do |pack, versions|
        a = []
        versions.each do |version, deps|
          perms = []
          sub_perms = dependencies_array(deps, processed)
          if sub_perms == []
            perms += [version]
          else
            sub_perms[0].each do |perm|
              perms << [version] + [perm].flatten
            end
          end
          a += perms
        end
        deps_array << a
      end

      deps_array
    end
Converts a simplified dependency tree into an array of dependencies,
 containing a sub-array for each top-level dependency. Each such sub-array
 contains, in its turn, version permutations for the top-level dependency
 and any transitive dependencies.