When Ram decided to leave his body and earth, he invited yamraj to take his soul. At that time, hanuman was the guardian of ayodhya, no one could cross the gates if hanuman didn't want them to.
Knowing hanuman's love for him, Ram knew hanuman won't let yamraj enter ayodhya. Ram called hanuman and sends him to retrieve his ring that he accidentally dropped in a small hole. Hanuman at that very instant, shrinked and dived into the hole. Through a really long way, he reached the end. There he saw piles and piles of same rings.
Nagraj was sitting there. He told hanuman how after every maha yuga, there's always one ring that is dropped here and a hanuman comes to take it. But they all fail.
He told him that this Ram is going to die now. But the cycle will repeat itself. There will be another Ram who will drop his ring to trick his hanuman and leave his body.
Moral :
It's one of those incidents which deals with continuity of time - Lord Rama or God with any other name has been present to help us all celebrate abundance of Joy & Happiness