如何比较Ruby 1.9中的两个文件?

时间:2021-10-31 15:59:49

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

在Ruby 1.8中,我将从“ftools”库中调用File.compare()来轻松比较两个文件的内容。

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

但是,在Ruby 1.9中,“ftools”被“fileutils”取代,后者没有“比较”方法。什么是等效电话?

2 个解决方案

#1


27  

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

啊,该方法已在FileUtils中重命名为compare_file。

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

两个版本中还有别名“cmp”。

#2


13  

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)

#1


27  

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

啊,该方法已在FileUtils中重命名为compare_file。

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

两个版本中还有别名“cmp”。

#2


13  

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)