Our Gemara on Amud Beis describes a legal process of rejecting a pending inheritance or acquisition:

 

With regard to an inheritance that comes to a person from another place, i.e., an inheritance one will receive in the future, a person can make a condition about it from the outset that he will not inherit it, since one can waive his future rights to property that is not currently his. 

 

Sod Yesharim (First Night of Pesach 46) discusses this legality in a metaphysical realm. One cannot control thoughts that might come to him, yet he can choose to dwell on them or he can shift focus. Furthermore, he says if one starts the day asking God to help him have proper thoughts and avoid evil thoughts, this matters spiritually, even if later he has an inappropriate thought or state of mind. The reason is that, at least he is declaring in advance that he does not wish to “acquire it”, similar to the legal ruling of our Gemara. Sod Yesharim then references a remarkable Aggadah (Avoda Zara 20a-b

), which I believe reflects a sophisticated psychological approach to thoughts deemed unwanted and unacceptable:

 

The Gemara raises an objection from a baraisa: There was an incident involving Rabban Shimon ben Gamliel, who was on a step on the Temple mount, and he saw a certain gentile woman who was exceptionally beautiful and said: “How great are Your works, O Lord!” (Psalms 104:24). And Rabbi Akiva too, when he saw the wife of the wicked Turnus Rufus he spat, laughed, and cried. He spat, as she was created from a putrid drop; he laughed, as he foresaw that she was destined to convert and he would marry her; he cried, as this beauty would ultimately be consumed by dirt.

 

And how would Rav explain the incident involving Rabban Shimon ben Gamliel, who praised the beauty of a gentile? The Gemara answers: Rabban Shimon ben Gamliel was giving thanks to God for creating such beautiful people rather than praising the gentile herself. As the Master said: One who sees beautiful or otherwise outstanding creatures recites: Blessed be He, Who has created such in His world.

 

But is it permitted to gaze upon a woman? The Gemara raises an objection from a baraita. The verse states: “And you shall keep yourself from every evil thing” (Deuteronomy 23:10); this teaches that a person should not gaze upon a beautiful woman, even if she is unmarried; and a person should not gaze upon a married woman, even if she is ugly;

 

and a person should not gaze upon the colored garments of a woman; and a person should not gaze at a male donkey, at a female donkey, at a pig, at a sow, or at fowl, when they are mating; and even if one were full of eyes like the Angel of Death and saw from every direction, it is not permitted to look. The Gemara answers: Rabban Gamliel did not intentionally look at the woman; rather, he was walking around a corner and he saw her unexpectedly as they each turned.

 

The paradox of unwanted thoughts is that by trying not to think them, we are automatically reinforcing them. Thoughts are electrical impulses in the nervous system. If one directs energy, even angry or impatient energy toward NOT thinking of them, it also directs energy to that neural pattern, reinforcing it as well. Consider this thought experiment: What is the  best way to overcome an irrational fear? Is it to think, “I MUST NOT be afraid. It is foolish to be afraid”, or is it to accept that there is fear, and fearful events, and to gently redirect thought and focus elsewhere?  The latter is a superior method as the key is to gently redirect thoughts instead of going about it impatiently or with shame and self-contempt. This is because all that energy reinforces the neural network of fear, by focusing on it. 

 

Notice how Rabbi Shimon Ben Gamilel and Rabbi Akiva acknowledged to themselves the attractiveness of the woman they encountered. Yes, as the Gemara says, they did not seek the encounter nor did they dwell on it. At the same time, they accepted the reality of the thought and the truth of it, then they let go and moved on, not through denial but acceptance of the full range of natural thoughts and feelings.