From: Florian Gross Date: 2005-01-12T21:11:17+09:00 Subject: Re: Comparing two files for equality Edgardo Hames wrote: > Hi everybody, Moin. > I tried to implement a program that > compares two files for equality. I came up with the following trivial > solution > > puts (IO.readlines file[0]) == (IO.readlines file[1]) > > Have you got any other suggestions? Not much different: 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 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.