From: "Jesús Gabriel y Galán" Date: 2008-05-14T22:10:23+09:00 Subject: Re: Handling of arrays On Wed, May 14, 2008 at 6:38 AM, Clement Ow wrote: > Jesús Gabriel y Galán wrote: > > > > Hope this helps, > > > > Jesus. > > thanks Jesus, that was really helpful! However I altered the code alil > cause ruby rendered an error to me saying that it cant convert Array > into string (hmmm, dunno if that's normal) for this line(suppose it's > for the arrays in the hash, exceptions_by_path): > > >files = exceptions_by_path.inject(Dir.glob("#{path}/*")) {|result, > ex| result.reject{|x| x =~ Regexp.new(ex)}} Sorry, that's what I get for not testing the code. I think (I'm a bit dense right now, so this might not work) that what I meant was this: exceptions_by_path = {} exceptions_by_path["/home/jesus"] = ["\.txt", "\.sql"] exceptions_by_path["/home/jesus/applications"] = ["\.sh", "\.bin"] # [...] and then paths.each do |path| files = exceptions_by_path[path].inject(Dir.glob("#{path}/*")) {|result, ex| result.reject{|x| x =~ Regexp.new(ex)}} end so you get the exceptions for that path, which is an Array that should work with inject as I was expecting. > And btw dont get me wrong, Struct is sweet too, just that i didnt want > to have a fixed number of exceptions for each path. ;) FileInfo = Struct.new :exceptions, :other_value, :yet_another paths_info = {} paths_info["/home/jesus"] = FileInfo.new(["\.txt", "\.sql"], "other value", "another") The number of exceptions is not fixed, as you can see above, I am storing an array in the :exceptions field, so each path can have a different number of exception patterns. Jesus.