From: Andreas Semt Date: 2005-01-13T02:03:30+09:00 Subject: Re: Comparing two files for equality Nicholas Van Weerdenburg wrote: > end is the end of an expression that returns an array. > > # this is quivalent. > a=files.map do |file| > ... > end > a.uniq > > # Since everything in ruby is an expression, you can do: > files.map do |file| > ... > end.uniq > > # making the expression explicit... > (files.map do |file| > .... > end).uniq > > Regards, > Nick > Thanks Nick! Nice Ruby code. It's every time a pleasure to see a solution by Florian. Greetings, Andreas > On Thu, 13 Jan 2005 01:15:25 +0900, Andreas Semt wrote: > >>Florian Gross wrote: >> >>>def files_equal?(*files) >>> files.map do |file| >>> File.size file >>> end.uniq.size <= 1 and >>> files.map do |file| >>> File.read file >>> end.uniq.size <= 1 >>>end >>> >> >>Could anybody please explain the "end.uniq.size" line? >>Thanks! >> >>Greetings, >>Andreas >> >> >>>This ought to be slightly faster in the average case. >>> >>>Other optimizations would be reading the files line-wise in parallel and >>>bailing out as soon as one of the lines differs. >>> >> >> > >