Rashi (Bamidbar 22.4.) says, that Balak was a midianite and Gemara (Sanhedrin 105:) says that he was a direct male-line ancestor of Ruth.
Why then Ruth is called Ruth, the Moabite?
Rashi (Bamidbar 22.4.) says, that Balak was a midianite and Gemara (Sanhedrin 105:) says that he was a direct male-line ancestor of Ruth.
Why then Ruth is called Ruth, the Moabite?
The simple explanation would be מדרשות חלוקות, that the midrash that identifies Balak as Tzur (Kozbi's father) does not mesh with the midrashim that Ruth was descended both from Balak and Eglon, but that's always unsatisfactory.
Here's my suggestion, no source: It is clear that Ruth was indeed a Moabite through male-line ancestry - otherwise, there would have been no question as to whether she was allowed to marry Boaz, and the drasha of עמוני ולא עמונית, מואבי ולא מואבית would have been irrelevant. However, it is not clear that her ancestry to these kings was through direct male-line ancestry. Ruth was not literally the daughter of Eglon (as in Sanhedrin 105b), nor the granddaughter of Eglon (as in Nazir 23b), as there were more than 200 years in between - see Tosfos to Nazir 23b, ד''ה בת בתו של עגלון. As such, it also does not necessarily follow that the descent - either from Ruth to Eglon, or from Eglon to Balak (if that was indeed so) - was through the male line only.
The Rashi (to Bamidbar 22:4) that you quote writes:
בעת ההוא. לֹא הָיָה רָאוּי לְמַלְכוּת, מִנְּסִיכֵי מִדְיָן הָיָה, וְכֵיוָן שֶׁמֵּת סִיחוֹן מִנּוּהוּ עֲלֵיהֶם לְצֹרֶךְ שָׁעָה :
At That Time — [Balak] that time: he was not really entitled to the kingdom; he was actually one of the Midianite princes, but when Sihon died they (the Moabites) appointed him as king over them to meet the needs of the time (Midrash Tanchuma, Balak 4).
We can deduce from here that while technically Balak was from Midian (ie a Midianite prince), when he was appointed Moabite king he was now considered to be a Moabite.