It more depends on how hard you intend to ride more than how far. If you are going to be riding hard then eating several hours before you ride is best. Personally I prefer eating about 3 hours before a race, if I don't I will cramp. I don't find it necessary to worry as much about it if I'm just going for a casual ride.

Now what you eat - carbs or protein is a bit more determined by how long you are going to ride. A fast short ride think more carbs, longer rides throw in some protein for sustained energy.