On Tue, 6 Jun 2006, Pete Yandell wrote:

> I've got to say, this is the least Ruby-ish Ruby I've ever seen! Someone has
> already pointed out Dir.glob, and that's probably the best approach, but
> even assuming you don't have that you can do:
>
>  array = Dir.entries(File.dirname("directory.rb")).grep(/tlb/)
>
> Even if, for some strange reason, you needed to write the loop yourself, you 
> could simplify it to:
>
>  array = []
>  direc.each do |file|
>    array << file if file =~ /tlb/
>  end
>
> Ruby has a lot of powerful methods for operations on Arrays. You should have
> a good read through the docs for Array and Enumerable!
>
> Pete Yandell
> http://9cays.com/

i realize it doesn't apply for most people, but i make a habit of always using
Dir.glob and other Dir operations with the block form.  the difference in
performance between

   Dir.glob(glob) do |path|
     ...
   end

and

   paths = Dir.glob(glob)

   paths.each do |path|
     ...
   end

becomes very important when directories contain more than 100,000 entries.
this rule can be generalized into 'always use the block form of methods unless
you have good reason not to'.  just thought i'd thow that out there since it's
bitten me once or twice.

regards.

-a
-- 
suffering increases your inner strength.  also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama