How do I compare two files in Ruby 1.9?

Craig Walker picture Craig Walker · Nov 24, 2011 · Viewed 16.5k times · Source

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?

Answer

Craig Walker picture Craig Walker · Nov 24, 2011

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

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