Project

General

Profile

Actions

Feature #2065

closed

An ancestors iterator

Added by bahuvrihi (Simon Chiang) over 15 years ago. Updated almost 13 years ago.

Status:
Rejected
Target version:

Description

=begin
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.
=end


Files

cache_benchmark.rb (1.79 KB) cache_benchmark.rb bahuvrihi (Simon Chiang), 03/19/2010 05:37 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0