From: Bill Mustard Date: 2005-10-26T00:07:03+09:00 Subject: Re: searching an array Ralph Smith wrote: > I have an array of classes source[] > > I can sort it like this > source.sort! { |x,y| x.fname <=> y.fname } > > If I print it out it is sorted by 'fname'. > > Now I would like to search it for different fnames but can't find an example of how to do that. > Can someone tell me how? > > thanks, > Ralph > > I like grep eg. results = source.grep(/.txt/) returns a list (array) of entries that contain '.txt'. (including things like fred.txt.bak) Array mixes in (includes) the methods in Enumerable which is where much of this magic is hiding. Bill