shorten/lib/create_short_link.rb
def recreate_on_collision(&does_collide)
    new_link = @short_link
    10.times do
      new_link = SecureRandom.urlsafe_base64(LENGTH)
      unless does_collide.call(new_link)
        @short_link = new_link
        break
      end
    end
  end
# In case of a collision attempt to recreate upto 10 times
In case of a collision attempt to recreate upto 10 times
In case of a collision attempt to recreate upto 10 times
def recreate_on_collision(&does_collide)
    new_link = @short_link
    10.times do
      new_link = SecureRandom.urlsafe_base64(LENGTH)
      unless does_collide.call(new_link)
        @short_link = new_link
        break
      end
    end
  end
def recreate_on_collision ( & does_collide ) new_link = @short_link 10 . times do new_link = SecureRandom . urlsafe_base64 ( LENGTH ) unless does_collide . call ( new_link ) @short_link = new_link break end end end
In case of a collision attempt to recreate upto 10 times
In case of a collision attempt to recreate upto 10 times
does_collide