As a graduate of starfleet academy, he knows many things. Of course he was there when first contact was made with the Ferengi in TNG season 1, and he had already completed his classes then, so not sure he actually learned the Ferengi rules at school. But I guess we will allow some continuity errors, esp if it might just be a joke on Worfs part.