Precautions
This experiment will work but since you are balancing a heavy object in the air you have a small margin for error. If you are heavy-handed with the equipment, knock into by accident or don't align the hammer and the ruler as instructed, then the hammer will be crashing down into the floor or even your foot. Set up a few pillows on the floor to make sure if something goes wrong that the hammer won't cause any damage.
The Experiment
Take your hammer and tie a piece of string around it tightly to keep it from coming loose. Make sure that you tie the hammer at the point where the handle ends and the rest of the hammer begins. Tie the other end of the string around a ruler at about the 1-inch mark. Leave about six inches of string between the ruler and hammer. When you pick the ruler up, the hammer handle should touch the ruler. Place it onto the edge of a table around an inch in. Move the string on the hammer slightly until the ruler is in line with the point of the hammer just before the head. Slowly let go and watch as the ruler balances with the weight of a hammer hanging on it.
Showing off your Project
Make a mark on the ruler to show you where the string ties before you demonstrate your project; this will save you time finding the exact point. Make sure to set up the project when you are being watched so everyone can see there are tricks in play. Leave the hammer balancing for a few minutes and allow those viewing it a closer look.
Explanation
Now that everyone is suitably amazed, it's time for an explanation. The center of gravity for the ruler is right in the center. The hammer's center of gravity is not in the middle but near the end because of the weight of the hammer head. So by joining the ruler to the hammer, the center of gravity for the whole construction is moved to a point under the table. This is why the ruler can balance on the edge of a table, despite the enormous weight pulling on it.