It teaches a lesson in ethical behavior.
The Book of Ruth, which appears in the third section of the Hebrew Bible--K'tuvim, Writings--is a beautiful folktale written in four short chapters. It celebrates the loyalty and reward of a young Moabite widow (Ruth) who chooses to follow her Israelite mother-in-law (Naomi) back to Bethlehem after Naomi was bereaved of her own husband and two sons. Ruth's sister-in-law, Orpah, who was married to one of the two deceased brothers, returns to her community, but Ruth decides to "cleave" to Naomi and share her fate in Judah.
Ruth's social status rises rather quickly. Starting as a nokhriyah, foreigner (Ruth 2:10), she next describes herself as a shif'hah, maidservant (Ruth 2:13), and then as an amah, handmaid (Ruth 3:9). By the end of the story, Boaz, her future husband, refers to her as an ishah, wife (Ruth 4:10), and the text hails her as an ancestress of King David (Ruth 4:17).
Jewish law assigns this book to the festival of Shavuot for various reasons. The events take place during the summer harvest when "Weeks" is celebrated; Ruth was the ancestress of David who, according to tradition, died on Shavuot; Ruth's acceptance of Judaism corresponds nicely with the Giving of the Torah in the desert to all of humanity; and Ruth's loyalty symbolizes the fidelity to the Torah that is expected of all Jews.
Although the story is set in the period of the Judges (1200-1000 BCE), it is unlikely that it was written at that time. According to the Talmud, "Samuel the prophet wrote his own books, Judges, and Ruth." (Baba Batra 14b) Most biblical scholars, however, argue for a postexilic date. Furthermore, as Rowley noted long ago, "The simple story of the Book of Ruth abounds in problems for which no final solution can ever be found, since the materials for their solution are denied us."
Why was this book written? The purpose is not apparent. Some say that it is simply "an interesting tale of long ago" (Pfeiffer). Others suggest that the author's goal was to promote the inclusion of outsiders, such as Ruth, in the Assembly of Israel (Smith), especially during the days of Ezra and Nehemiah, who pursued an anti-foreigner policy. Driver claims that the goal was to establish David's genealogy. For Vellas, family unity is at the center of the story. Recently, Adele Berlin maintained that the book is about "exile and return, land and people."
I agree with J. Sasson that the most reasonable rationale is this: The author wished to stress that common people can do the right thing when they act unselfishly toward one another, as witnessed by the main characters in the book. This echoes the ancient rabbis who said that the Book of Ruth was written to teach us a lesson in gemilut hasadim, acts of loving-kindness (see Ruth Rabbah 2:15). It is this universal message that makes the idyllic Book of Ruth extremely appealing to everyone.