Method: Graph#invert
- Defined in:
- lib/graph.rb
#invert ⇒ Object
Creates a new Graph whose edges point the other direction.
261 262 263 264 265 266 267 268 269 |
# File 'lib/graph.rb', line 261 def invert result = self.class.new edges.each do |from, h| h.each do |to, edge| result[to][from] end end result end |