Modern-day gas pumps have two parts: the mechanical part that uses valves and an electric pump to get the fuel out of the storage tanks into your car, and the electronic "brain" of the system, which consists of a computer driving the pump's actions, controlling the readouts and speaking with the point-of-sale interface inside the gas station.
By the end of the nozzle is a hole and a pipe that connects the hole to the handle. When your tank is not full, air is pulled through this hole by a vacuum that accompanies the process of sucking the gasoline into your gas tank. However, when the gas in your tank reaches a high-enough level to fill this hole, the pipe sends a message to the handle, and the nozzle is flipped off.
A static electricity field can develop when you fill a gas can unless you use the pavement as a grounding tool. Static electricity and gasoline aren't friends, and you can end up with an explosive situation. Also, just because the guy two pumps over is smoking and nothing bad has happened doesn't mean you need to. All it takes is one ignition, and the whole gas station could go up in a hurry.