Compare Ruby Arrays Online
Paste two Ruby arrays (as JSON). See what was added, removed, or changed — element by element.
🔒 100% private — runs entirely in your browseror try sample data
Paste two Ruby arrays (as JSON). See what was added, removed, or changed — element by element.
🔒 100% private — runs entirely in your browseror try sample data
Ruby Array Compare diffs two Ruby arrays element by element and shows you exactly what changed. Ruby provides the - operator for array difference, but it only shows elements in the first array not present in the second — it doesn't show additions, modifications, or preserve index positions.
Ruby arrays are ordered, integer-indexed collections that can hold any object — strings, numbers, hashes, other arrays, or even mixed types. Ruby's expressive array methods (map, select, reject, zip) are powerful, but none give you a visual diff of two arrays.
Paste your arrays as JSON (e.g., ["a", "b", "c"]). Convert Ruby symbols to strings and hashes to JSON objects. The tool compares at any nesting depth.
arr1 = ["rails", "sinatra", "rspec", "sidekiq"]
arr2 = ["rails", "hanami", "rspec", "sidekiq", "dry-rb"] removed = arr1 - arr2 # ["sinatra"]
added = arr2 - arr1 # ["hanami", "dry-rb"] puts "Removed: #{removed}"
puts "Added: #{added}"Array#- removes matching elements but doesn't show position or handle nested structures.
require 'set' a = Set.new([1, 2, 3, 4])
b = Set.new([3, 4, 5, 6]) puts (a - b).to_a # [1, 2] — only in a
puts (b - a).to_a # [5, 6] — only in b
puts (a & b).to_a # [3, 4] — in both
puts (a | b).to_a # [1, 2, 3, 4, 5, 6] — unionSet operations are clean but discard duplicates and ordering information.
arr1 = ["rails", "sinatra", "rspec"]
arr2 = ["rails", "hanami", "rspec", "puma"] max = [arr1.length, arr2.length].max
max.times do |i| v1 = i < arr1.length ? arr1[i] : "(missing)" v2 = i < arr2.length ? arr2[i] : "(missing)" puts "[#{i}]: #{v1} -> #{v2}" if v1 != v2
end
# [1]: sinatra -> hanami
# [3]: (missing) -> pumaManual index comparison works for flat arrays but breaks down with nested hashes.
:foo == "foo" is false in Ruby — symbols and strings are different types. When pasting data here, convert symbols to strings. JSON does not have a symbol type.
[1, 1, 2, 3] - [1] returns [2, 3], removing both 1s. If you need to remove only the first occurrence, use delete_at with index, or use this tool for a position-aware diff.
Since Ruby 1.9, hashes maintain insertion order. When comparing arrays of hashes, the order of keys affects == comparison. {a: 1, b: 2} == {b: 2, a: 1} is true in Ruby, but JSON stringification order may differ.
Paste your Ruby arrays as JSON (e.g., ["a", "b", "c"]) into the two panels and click Compare. Convert Ruby symbols to strings and hashes to JSON objects.
Array#- returns elements in the first array that are not in the second array. It removes all occurrences and doesn't show additions or index-level changes.
Yes. Convert hashes to JSON objects ({"key" => "value"} becomes {"key": "value"}). The tool compares all key-value pairs recursively.
Yes. This tool runs entirely in your browser. No data is sent to any server.
Yes. The tool performs deep recursive comparison, showing changes at any nesting depth.
Yes. Check "Ignore array order" to compare arrays as unordered collections, similar to Ruby Set comparison.