Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare two files in Ruby 1.9?

Tags:

In Ruby 1.8, I would call File.compare() from the "ftools" library to easily compare the contents of two files.

However, in Ruby 1.9, "ftools" is replaced by "fileutils", which doesn't have a "compare" method. What's the equivalent call?

like image 331
Craig Walker Avatar asked Nov 23 '11 23:11

Craig Walker


People also ask

Can I compare 2 files in Visual Studio?

locate the required file in the Solution Explorer window, right-click it and choose Compare Selected File in the context menu; open the required file in Visual Studio, right-click the required document name in the document tab well and in the document's context menu select Compare Current File.


2 Answers

Ahh, the method has been renamed to compare_file in FileUtils.

There's also an alias of "cmp" in both versions.

like image 194
Craig Walker Avatar answered Dec 01 '22 01:12

Craig Walker


Old question, but I just got here from google. identical? is available for those who like me prefer that coding style.

FileUtils.identical?(exp, act) 
like image 34
thele101 Avatar answered Dec 01 '22 01:12

thele101