Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created February 17, 2012 20:16
Show Gist options
  • Save jdjkelly/1855208 to your computer and use it in GitHub Desktop.
Save jdjkelly/1855208 to your computer and use it in GitHub Desktop.
Comparing Two Arrays in Ruby
list1 = Array.new
list2 = Array.new
exist = File.open("exist.txt").each_line {|line| list1 << line.gsub(/\s+/, "")}
tocheck = File.open("tocheck.txt").each_line {|line| list2 << line.gsub(/\s+/, "")}
list2.each do |line|
if list1.include?(line)
File.open("output.txt", 'w') {|f| f.write(line) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment