It would make since for David to write it as Ruth was one of his progenitors.
Matt 1:
"5And Salmon begat Booz of Rachab; and Booz begat Obed of Ruth; and Obed begat Jesse;
6And Jesse begat David the king; and David the king."
Ruth 4:
" 17And the women her neighbours gave it a name, saying, There is a son born to Naomi; and they called his name Obed: he is the father of Jesse, the father of David.
18Now these are the generations of Pharez: Pharez begat Hezron,
19And Hezron begat Ram, and Ram begat Amminadab,
20And Amminadab begat Nahshon, and Nahshon begat Salmon,
21And Salmon begat Boaz, and Boaz begat Obed,
22And Obed begat Jesse, and Jesse begat David."
What I don't understand is, wasn't there a law pertaining to the offspring from the union of an Israelite and a non-Israelite?
Deuteronomy 23. Yet apparently, biologically, David's grandmother, Ruth (Moabite) as well as his great grandmother, Rachab (Canaanite?") were non-Israelite. So how does David get away with being king. And Solomon built the temple. Solomon had his share of foreign wives as did kings of both Judah and Israel.
Deuteronomy 23: 3An Ammonite or Moabite shall not enter into the congregation of the LORD; even to their tenth generation shall they not enter into the congregation of the LORD for ever:
And this is also the lineage of Jesus, being: 28 generations descended from David.
One other thing that I have noted is that the purpose of Boaz marrying Ruth; "And Boaz said unto the elders, and unto all the people, Ye are witnesses this day, that I have bought all that was Elimelech's, and all that was Chilion's and Mahlon's, of the hand of Naomi.
10Moreover Ruth the Moabitess, the wife of Mahlon, have I purchased to be my wife, to raise up the name of the dead upon his inheritance, that the name of the dead be not cut off from among his brethren, and from the gate of his place: ye are witnesses this day."
Yet it is Boaz whose name is given in the genealogies. What happened to the raising up the name of Mahlon?