If riding away is not possible, there is nearly never a real problem. Some cyclists recommend bludgeoning the dog with car ariels, whips, pumps, clubs, and other things which could really hurt a dog. Almost every time, if you simply stop, dismount, and face the dog directly, it will trot up to you with it's tail wagging. Most dogs are normally friendly, but all of them seem to go nuts when exposed to a moving bicycle. Unless you can determine that the dog really is a threat, anything more than a water bottle squirt really is brutal and uncalled for.
If you stop your bike and the dog remains aggressive, you have yourself a showdown. The whole point of being a Homo Sapien is that we get to use tools. With that in mind, there are quite a selection of weapons available for the cyclist being attacked by a dog:
Some of these methods might be also be useful to inner city slum riders, if there are any.
Aerosol Pepper Sprays
There are very effective, are light enough to clip to your bike or shorts, and cause no permanent harm. The MACE brand formulation (a combination of a nasal and eye irritant and a tear gas) is not effective on dogs or animals, so do not rely on it.
Keep in mind that pepper spray will suffer a shorter range if you are firing while riding, due to the wind, and that it may blow back onto you if you fire into the wind (especially that relative to the bicycle). It is also difficult to aim accurately and ride at the same time, so using it while dismounted is the best bet. Some formulations may take up to a few seconds to take effect.
Products like the "DAZER" are a small ultrasonic sound generator that you point at the dog, producing an uncomfortable but harmless sound that is audible to dogs, but not to humans.
Ammonia Squirt Gun
While a good deal less convenient than a can of pepper spray, they are indeed effective. The dog will generally stop dead in its tracks, and start to roll around on the road if you shoot it with this. It also works pretty well on the occasional redneck who tries to jump you for your bike. Use a water ammonia solution, from the grocery store. Pure (anhydrous) ammonia is dangerous overkill and can give you frostbite, or sear your own lungs at the least.
Pure ammonia is not a very friendly substance. It will burn if involved in a fire, explode if mixed with air between 16 and 25%, and is toxic. It forms explosive compounds with silver, chlorine, mercury, and several other chemicals. It is corrosive to copper and zinc and their alloys.
Ammonia is considered to be harmful by all exposure means. Effects from exposure may be delayed. Can kill if swallowed. Skin contact with the liquid may cause frost bite, first or second degree burns and if extensive, may be fatal. Liquid contamination of eyes can result in permanent injury and blindness, the onset of which maybe delayed for 8 10 days. The gas causes watering of the eyes and is a severe irritant to the eyes, respiratory tract and moist areas of the skin. Ammonia is an asphyxiant. Inhalation of high concentrations may cause severe breathing difficulty, chest pain and lung damage including pulmonary oedema which may be fatal. If you are considering using ammonia, please read this chemical fact sheet about ammonia, its effects, and first aid.
Try to ram it down his throat. While generally too lightweight to be a good bludgeon, it's just the right size to suffocate a dog with, or to use as an aid to strangle it. It can also be used as a jabbing weapon which concentrates impact force enough to readily to break ribs, especially if you tangle the dog up in your bike first, so that you can use your body weight.
A large rock or a stick have enough mass to soak up a good deal of force, and then dissipate it very quickly against a dog's skull. If your brakes and quick-release hub are expensive enough to allow your front wheel to be removed quickly enough, your rims will probably be too lightweight and expensive to be very useful. Keep in mind that humans are excellent at throwing things with precision and force.
See also our article on Dealing With Dogs for tips and techniques before, while, and after you play with the aforementioned items.