While the ridge board length on a gable roof is simple, a hip roof is only slightly more difficult to figure. A gable ridge is the same length as the building plus the overhang on either end. A hip roof ridge is the width of the structure, plus the thickness of the ridge, subtracted from the buildings length.
To find the ridge board length you simply measure the length of the building, then the width, add the ridge thickness to the building width, and subtract this total from the length.
I will walk you thru the steps I use to find the ridge length for a 12 foot by 28 foot building requiring a simple hip roof.
At this point the pitch of the roof doesn't matter, we need to find the run of the common rafter. Measure the width of the building and mark the exact center, 12 feet divided by 2 = 6 feet. This is the center of the ridge, now lay out the thickness of the ridge. If the ridge is 1 1/2 inches thick make a mark 3/4 of an inch on either side of this line. Measure from the outside corner to the marks that represent the ridge. You should come up with 5' 11 1/4".
Now measure along the length of the building from both ends and mark 5' 11 1/4", now if you measure between these two marks you will have the length of the ridge board.
Notice how it works out, length minus width plus 1 1/2 inches.
If you're not confident cutting the ridge to length before putting it up there is a different way of cutting it to length. Instead of putting up the common rafters on the very end use the ones one layout mark from where you think the ridge should end and leave it a foot long or so. Then just use the king common to mark the cut on the end of the ridge.