While searching for another link I bumped into this perfect example of making music on the spot and a darn good method for training your ears and becoming a flexible and versatile player.
Watch the late great Ravi Shankar and his daughter Anoushka - he sings a phrase and she plays it!
This is an exercise you can do by yourself or with a friend:
- Sing the first thing that comes to your mind - make it a short phrase at first, but always aim for intonation, dynamics and interesting rhythmic combinations - Emulate it with the guitar - don't hurry and don't think in terms of scales, arpeggios and such.. just play what you hear, by searching the notes on the neck and putting them together until you manage to sound like the thing you sung (Remember to make it short at first so that you won't forget it!) - AFTER finding it - analyze it and see what you actually played that in terms of theory
The more you do it, the better you will become, so implement it in your daily practice schedule and see how it goes