class RBS::EnvironmentWalker

EnvironmentWalker provides topological sort of class/module definitions.

If a method, attribute, or ancestor in a class definition have a reference to another class, it is dependency.

walker = EnvironmentWalker.new(env: env)

walker.each_strongly_connected_component do |scc|
  # Yields an array of strongly connected components.
end

The only_ancestors! method limits the dependency only to ancestors. Only super classes and included modules are dependencies with the option. This is useful to calculate the dependencies of class hierarchy.

walker = EnvironmentWalker.new(env: env).only_ancestors!

walker.each_strongly_connected_component do |scc|
  # Yields an array of strongly connected components.
end