Today's Gospel reading at Mass came from Luke 18. Jesus addressed a parable to those who were convinced of their own righteousness and despised everyone else. In the story a Pharisee and a tax collector went up to the temple area to pray. The Pharisee took up his position and prayed, "O God, I thank you that I am not like the rest of humanity ~ greedy, dishonest, adulterous ~ or even like this tax collector. I fast twice a week, and I pay tithes on my whole income." But the tax collector stood off at a distance and would not even raise his eyes to heaven but beat his breast and prayed, "O God, be merciful to me a sinner." Jesus told that the latter went home justified, not the former. Then came the punch line: "Everyone who exalts himself will be humbled, and the one who humbles himself will be exalted."
It is clear that being self-righteous amounts to self-glorification, succumbing to one's own pride, while remaining humble keeps you connected to God.