Depending on how you want to express "similar", you could do something like this:
def count_similar(a, lower_bound, upper_bound)
a.count { |h| h[:top] >= lower_bound && h[:top] <= upper_bound }
end
a = [{top: 10, left: 20}, {top:10, left:10}, {top: 10, left: 123},
{top:500, left:10} , {top:2, left: 50}, {top:2, left:400}]
count_similar(a, 1, 19) #=> 5