How to create a simple code which will change obj color depending of distance(using Lerp)

I have no idea. Can someone help me?
Please

Something like this ?

public Color DistanceToColorLerp(Vector3 a , Vector3 b , Color closeCol , Color farCol , float maxDistance)
{
       float ratio = Vector3.Distance(a , b) / maxDistance;
       return Color.Lerp( closeCol , farCol , ratio); // note : Lerp internally clamps ratio between 0 and 1
}

Then you can just take the return of the method and assign it to your desired object