hashdiff
hashdiff copied to clipboard
Unexpected results
a = {a:'car', b:['truck', 'plane'] }
b = {a:'bus', b:['truck', ' plan'] }
diff = HashDiff.diff(a, b) do |path, obj1, obj2|
case path
when 'b[*]'
true
end
end
=> [["~", "a", "car", "bus"], ["-", "b[1]", "plane"], ["+", "b[1]", " plan"]]
vs.
a = {a:'car', b:['truck', 'plane'] }
b = {a:'bus', b:['truck', ' plan'] }
diff = HashDiff.diff(a, b) do |path, obj1, obj2|
case path
when 'b[*]'
false
end
end
=> [["~", "a", "car", "bus"], ["-", "b[1]", "plane"], ["+", "b[1]", " plan"]]
vs.
a = {a:'car', b:['truck', 'plane'] }
b = {a:'bus', b:['truck', ' plan'] }
diff = HashDiff.diff(a, b) do |path, obj1, obj2|
case path
when 'b[*]'
raise "#{obj1} == #{obj2}"
end
end
=> [["~", "a", "car", "bus"], ["-", "b[1]", "plane"], ["+", "b[1]", " plan"]]
It doesn't seem to make any difference what goes in the block as a custom comparator.
Also, when I do a puts
inside the block to try and figure out what is going on there is no output?!
The raise
is silently rescued?!
Hi @pboling Could you please check if it works on master branch? It's been fixed but not released yet.