Simple recursive implementation of a topological sort in Ruby.