Edgardo Hames <ehames / gmail.com> Jan 12, 2005 at 01:26 PM wrote:
>After reading "Refactoring for PL/SQL Developers" in January's Oracle
magazine, 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 other suggestions?

I came up with this:

class File
SIZE =1024
include Comparable
def <=> f # Does not rewind, before or after.
	s1 =s2 =s =n =0 # Efficiency.
	begin # At least once.
		s1 ,s2 =[ self ,f].collect do |a|
			s =a.read( SIZE)
			s ? s :String.new # Or ''.
		end
	end while	0 ==( n =(s1 <=>s2)) &&
			SIZE ==s1.length
	n # Return.
end
end # class File

Kind regards,