Praise be to Allah.
Your friend has to realize that that this habit is haraam according to sharee’ah, as is indicated in the Book of Allaah and the Sunnah of His Prophet (peace and blessings of Allaah be upon him). We have already quoted the evidence in detail in question no 329. This habit is something that is repulsive to sound human nature and reason, and it is not befitting for a Muslim to lower himself to this level.
It should also be noted that sin has negative consequences a person, in this world and in the Hereafter, if he does not repent and if Allaah does not bestow His mercy upon him. We have already discussed this in the following questions: 23425, 8861 .
This habit has many harmful effects, such as weakening the body, and increasing the gulf between a person and his Lord. It is one of the major factors in depression.
With regard to the matter mentioned in the question, if he ejaculated as a result of masturbation then his fast is invalidated and he has sinned; he has to refrain from eating and drinking for the rest of the day, and he also has to make up that day.