A simple implementation of topological sort in Ruby