This can be done without a loop, example:
    unless posixaccount.entry.objectclass.include?('ldapPublicKey')
      # add the ldapPublicKey object class
    end