From: Tomasz Wegrzanowski Date: 2010-07-24T10:33:30+09:00 Subject: [ruby-core:31469] [Feature #3608] Enhancing Pathname#each_child to be lazy Feature #3608: Enhancing Pathname#each_child to be lazy http://redmine.ruby-lang.org/issues/show/3608 Author: Tomasz Wegrzanowski Status: Open, Priority: Normal Right now it lists entire directory, then yields every element, that is x.each_child(&b) means x.children.each(&b). This is too slow for directories mounted over networked file systems etc., and there is currently no way to get lazy behaviour, other than leaving convenient #each_child/#children API and moving to lower level. With this patch: * #children is eager like before, no change here * #each_child becomes lazy * #each_child without block returns lazy enumerator, so it can be used like this dir.each_child.find(&:symlink?) without losing laziness. Patch is against trunk. pathname.rb was in lib/ not ext/pathname/lib/ before, but it works either way. The part to return enumerator when called without a block wouldn't work in 1.8. If backport is desired, that line would need to be thrown away, and #children would need to build result array instead of calling each_child(with_directory).to_a - this would be straightforward. ---------------------------------------- http://redmine.ruby-lang.org