From: MenTaLguY Date: 2007-10-18T03:01:59+09:00 Subject: Re: How to combine blocks and recursiveness On Thu, 18 Oct 2007 02:40:09 +0900, Luis wrote: > def scan > @path.each_entry do |p| > next if p.to_s == "." || p.to_s == ".." > p = @path + p > if p.file? > finf = FileInfo.new(p) > @files << finf > elsif p.directory? > dinf = DirInfo.new(p) > dinf.scan # ==> Recursive search of subdirs > end > end > yield @path, @files > end Another poster mentioned the &block thing, which is probably preferable. Note that you could also simply do: dinf.scan { |p,f| yield p,f } The advantage to this is that (for shallow recursion), there is less overhead than creating a Proc object for the block. The big disadvantage is that you add an extra layer of yield-ing for each level recursion. -mental