I want to delete the first 3 duplicate entries -

I wrote a code :

def del_first_three(a)
  num_to_del = a.find { |e| a.count(e) >= 3 }
  return a if num_to_del.nil?
  3.times do
    ind = a.index { |e| e == num_to_del }
    a.delete_at(ind)
  end
  a
end

del_first_three([3,4,5,3,3])

But at the method end I put `a`, to return the resultant array, which I
don't like. So I took the help of `#tap` as below :

def del_first_three(a)
  num_to_del = a.find { |e| a.count(e) >= 3 }
  return a if num_to_del.nil?
  3.times do
    ind = a.index { |e| e == num_to_del }
    a.tap { |ob| ob.delete_at(ind) }
  end
end

del_first_three([3,4,5,3,3]) # => 3

But it is also helpless, as `Integer#times` returns `self`. Is there any
method to meet my need. I am actually looking for a method, which work
as `File:open` with block.

-- 
Posted via http://www.ruby-forum.com/.