Pig stick
I believe the method is to rig a "pig stick" to a masthead halyard so that the top of the stick hangs down, until the line flips the stick upwards as it gets to the top of the mast/sheave. This is the proper method to fly a burgee on a sailboat. However, with all sorts of devices at the masthead on modern boats, I have not seen it done.