It's in the game code that 10 (I think it's that number.. Definitely multiple, anyway) watermelons make 100% chance of a girl and same with apples for a boy. It's literally in the game code - one doesn't do it, you just got lucky.
This is something I personally want to get to the bottom of. I've seen on multiple sites conflicting information - at SimsWiki, the chance is increased by 10% every time you eat a fruit to a maximum of 50%. I'm researching this thoroughly.
Edit: I've done.
The chance increases by 10% in the favorable gender every time you eat a fruit.
The base chance is 0.5 to get a boy or a girl - the equivalent of flipping a coin. Every time you eat an apple, the chance for a boy is skewed - so if the coin is Heads for Boys and Tails for girls, it's like altering the head to be more likely to land upright. The same goes for girls.
So if I ate 3 apples, then the chance for a boy would be 50+10+10+10 - or 80%.
Long story short, to guarantee a baby boy, you need to only eat
5 apples, and to guarantee a baby girl,
5 watermelons.