Feature #2065: An ancestors iterator
http://redmine.ruby-lang.org/issues/show/2065

Author: Simon Chiang
Status: Open, Priority: Low

I have implemented DSLs that add features to a class/module that should be inherited like methods.  In those cases I end up iterating ancestors to find the first time a feature has been added (the same way I imagine methods are determined).

The issue is that SomeClass.ancestors regenerates the ancestors array each time it is called.  Therefore this is relatively slow:

  SomeClass.ancestors.each do |ancestor|
    # ...
  end

It would be nice if there were a method that iterates ancestors without generating the ancestors array:

  SomeClass.each_ancestor do |ancestor|
    # ...
  end

This could improve the performance of DSLs that want to support method-like inheritance.


----------------------------------------
http://redmine.ruby-lang.org