From: Venkat Kumar Date: 2009-02-26T14:04:56+09:00 Subject: Re: require 'diff/lcs/Array' Hi , Thanks a lot for all ur replies.. My problem is I could't require 'diff/lcs'. I am getting an error message like. c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- diff/lcs/Array (LoadError) Should I install any additional gem. kindly help me Thanks, venkat Daniel Berger wrote: > On Feb 25, 10:55�am, James Gray wrote: >> On Feb 25, 2009, at 11:17 AM, Venkat Kumar wrote: >> >> > I need compare two text files. I should require 'diff/lcs/Array' � >> > when i >> > do this iam getting error. >> >> I've tried using that library in the past, but its interface just � >> makes it crazy hard to work with. > > I came up with this for diff'ing 2 files and spitting the results to > stdout. It's meant to simulate "diff -u" output, but it's not quite > identical and is definitely not tested thoroughly: > > # diff_test.rb > require 'diff/lcs' > > # The file 'test1.txt' contains the following 3 lines: > # > # This is a house > # Hello World > # My favorite color is blue > # > # The file 'test2.txt' contains the following 3 lines: > # > # This is a car > # Hello World > # My favorite color is green > > module Diff > module LCS > def self.diff_files(file1, file2) > array1 = IO.readlines(file1) > array2 = IO.readlines(file2) > diffs = diff(array1, array2) > > print diffs.first[0].action * 3 + ' ' > print file1 > print "\t" + File.mtime(file1).to_s > > puts > > print diffs.first[1].action * 3 + ' ' > print file2 > print "\t" + File.mtime(file2).to_s > > puts > > diffs.each_with_index{ |diff, i| > diff.each{ |d| > puts d.action + d.element > } > } > end > end > end > > Diff::LCS.diff_files('test1.txt', 'test2.txt') > > Here was the output of Diff::LCS.diff_files: > > --- test1.txt Wed Feb 25 12:18:42 -0700 2009 > +++ test2.txt Wed Feb 25 12:18:53 -0700 2009 > -This is a house > +This is a car > -My favorite color is blue > +My favorite color is green > > Hope that was useful. > > Regards, > > Dan -- Posted via http://www.ruby-forum.com/.