You could just make the logic a bit more generic so that it has a target and returns a location. Then iterate through each of your gems (they need to be stored somewhere) telling each one to follow the gem before it. This will create the worm/snake effect
Essentially the first gem follows the player then each gem follows the gem in front of it.