From: dblack@... Date: 2003-09-30T03:07:40+09:00 Subject: Re: Dir.foreach not with patterns? Hi -- On Tue, 30 Sep 2003, Paul Duncan wrote: > * Gavin Sinclair (gsinclair@soyabean.com.au) wrote: > > On Wednesday, September 24, 2003, 12:33:54 AM, Alan wrote: > > > > > ts wrote: > > >> next if f == "." or f == ".." > > > > > I did used to do that. I can't even remember why I changed it to a regexp! > > > > Come on, you can't resist. > > > > class Object > > def in?(enum) > > enum.include?(self) > > end > > end > > > > ... > > next if f.in? [".", ".."] > > ... > > or > next if %w{. ..}.include? f > > but personally i prefer this: > > next if f =~ /^\.\.?$/ However.... $ ruby -e 'File.new("abc\n..\ndef","w")' $ ruby -e 'Dir["abc*"].each {|f| > puts "#{f}: yes" if /^\.\.?$/.match(f)}' abc .. def: yes I know, I know, not likely :-) Still, /\A\.\.?\z/ would be safer. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav