adamscott adamscott - 1 year ago 114
Ruby Question

Ruby array inspection of a text file converted to array using readlines

I am converting two text files to an array using readlines

f1 ='current_routes.txt')
f2 ='production_routes.txt')

file1lines = f1.readlines
file2lines = f2.readlines

puts file1lines.inspect
puts ''
puts file2lines.inspect

The two files are an exact copy and paste of each other:

["DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.\n", "Please register a mime type using `register_mime_type` then\n"]

["DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.\r\n", "Please register a mime type using `register_mime_type` then\r\n"]

Why does inspect on the first file add \n and inspection of the second file add \r\n?

I am trying to compare the files for differences and this is giving me trouble

Answer Source

Guessing you're on a Windows machine and the copy is adding in \r. Try this:

file1lines =
file2lines =

String#chomp will remove either \n or \r\n. Then you can compare the rest of the string.