The best way I've found is to think of it as a variation on the graduated neutral density filter theme.
Imagine the archetypal example, of a straight horizon, where you'd position the filter's transition on said horizon. Take two shots, one properly exposed for sky and the other for foreground. Put them as separate (aligned) layers in Photoshop (etc.). Add a mask to the upper layer, and use the gradient tool to create the same transition as the filter would have. The advantage, of course, is that you have complete control over how hard / soft the "filter" is, and over how many "stops" it is.
Now, imagine that the horizon isn't flat, but instead has a very prominent mountain peak sticking up out of it covering half the sky. If all you had was a filter, you'd be screwed. But, use this same technique and, rather than the gradient tool, use a very very large soft brush to create a custom-shaped mask, and you've got a custom-made GND filter just for your scene, something that would be insanely expensive if you tried to do it with tinted glass.
Extending the technique to even more complex scenes is easy to imagine from there. All you're doing is masking in and out the different exposures and thereby creating a virtual multi-step odd-shaped graduated neutral density filter.