(Exodus 12:29:) "And it came to pass at midnight that the LORD smote all the firstborn." This is what Scripture says (in Psalm 119:62): "At midnight I will arise to give thanks to You." David said: I am obligated to arise and give thanks to You for what You did with my grandfather and with my grandmother at midnight. When? At the time when Naomi and Ruth the Moabite, her daughter-in-law, returned. What is written? "And the whole city was stirred over them, and they said: Is this Naomi?" (Ruth 1:19). This is the one who used to walk in a covered carriage. This Naomi is the one who used to walk about clothed in fine wool, "those who were raised in scarlet" (Lamentations 4:5). The two of them dwelt together in one house. "And Naomi said to her: My daughter, shall I not seek rest for you?" (Ruth 3:1). From here they said that a woman has no rest in her father's house, but only in her husband's house. "And now, is not Boaz our kinsman" (Ruth 3:2). What is "our kinsman" (moda'tanu)? He is of our near relations, as it is said: "The man is near of kin to us" (Ruth 2:21). And why did the prince of the generation go out and sleep in the threshing floor? Rather, because the generation was very licentious, he went out and slept in the threshing floor in order to fence in the licentious. Now, "you shall wash and anoint yourself" (Ruth 3:3) — she did not do so. Rather, Ruth was very modest. She said: Whoever would see me thus would say, "What has this harlot done?" "And she went down to the threshing floor and did according to all that her mother-in-law commanded her" (Ruth 3:6). Only after she went down did she do all that her mother-in-law had commanded her.
David's Midnight Thanks for Ruth, Naomi, and Boaz at the Threshing Floor
Midrash Tanchuma Buber, Bo 16:1
ויהי בחצי הלילה וה' הכה כל בכור וגו' (שמות יב כט). זש"ה חצות לילה אקום להודות לך (תהלים קיט סב), אמר דוד חייב אני לעמוד ולהודות לך, על מה שעשית עם זקיני ועם זקינתי בחצות הלילה, אימתי בשעה שחזרה נעמי ורות המואביה כלתה, מה כתיב ותהום כל העיר [עליהן ותאמרנה הזאת נעמי] (רות א יט), זו היא שהיתה מהלכת (באיסקופיא סתטא) [באיסקופיסטא], נעמי זו היא שהיתה מהלכת ולובשת מילתין, האמונים עלי תולע וגו' (איכה ד ה), ישבו שתיהן בוך בית אחד. ותאמר [לה] נעמי (אל רות כלתה) [חמותה] בתי הלא אבקש [לך] מנוח וגו' (רות ג א), מיכאן אמרו שאין לאשה מנוח בבית אביה כי אם בבית בעלה, ועתה הלא בועז מודעתנו (שם שם ב), מהו מודעתנו מקרובינו הוא, (הלא) [שנאמר] קרוב לנו האיש וגו' (שם ב כא). ונשיא של דור למה היה יוצא וישן לו בגורן, אלא שהיה הדור פרוץ הרבה, והיה יוצא וישן בגורן, בשביל לגדור את הפרוצים, אלא ורחצת וסכת (שם ג ג) לא עשתה כן, אלא רות היתה נקיה הרבה, אמרה מי שהיתה רואה אותי כך, אומר זונה זו מה עשתה, ותרד הגורן [ותעש ככל אשר צותה חמותה] (שם שם ו), משירדה עשתה כל מה שצותה חמותה.