It is harder to be nice if you don't feel well, and if your grandfather suddenly started being rude to people in that last year, maybe he was in pain or suffering other effects of disease. And then, some older people figure that they have done stuff for other people all their lives and now it is time for them to do and say exactly what they want, when they want, regardless of whether it is considered rude.
I am often tempted to issue a quick retort, and in working on that I started gritting my teeth instead of speaking, as if actually holding in physical objects instead of words. That little habit prevented me from saying things that would not have been very nice, even if some of them were actually hysterically clever, but it did some expensive damage to dental work.
Not a good solution.
I considered keeping duct tape in my pocket, to plaster across my face at the appropriate time, but that would require keeping something sharp to cut it with, and that might be even more dangerous.
Now I just look away from my intended victim. Breaking the eye contact helps give me a moment to draw in a breath and rethink.
And I don't think there is a "mean gene".