An act is virtuous through being directed by reason to some virtuous [honestum] [Cf. 145, 1] good. Now this is consistent with fasting, because fasting is practiced for a threefold purpose.
First, in order to bridle the lusts of the flesh, wherefore the Apostle says (2 Corinthians 6:5-6): "In fasting, in chastity," since fasting is the guardian of chastity. For, according to Jerome [Contra Jov. ii.] "Venus is cold when Ceres and Bacchus are not there," that is to say, lust is cooled by abstinence in meat and drink.
Secondly, we have recourse to fasting in order that the mind may arise more freely to the contemplation of heavenly things: hence it is related (Daniel 10) of Daniel that he received a revelation from God after fasting for three weeks.
Thirdly, in order to satisfy for sins: wherefore it is written (Joel 2:12): "Be converted to Me with all your heart, in fasting and in weeping and in mourning." The same is declared by Augustine in a sermon (De orat. et Jejun. [Serm. lxxii (ccxxx, de Tempore)]): "Fasting cleanses the soul, raises the mind, subjects one's flesh to the spirit, renders the heart contrite and humble, scatters the clouds of concupiscence, quenches the fire of lust, kindles the true light of chastity."
St. Thomas Aquinas, Summa Theologiae 2-2.147.1