What caused Ruka to change? What caused


   Ruka to become a girl?


In episode 8, they jokingly try to alter


   Ruka's gender to make her a girl


with a D-Mail, but what they do is scientifically crude and unlikely to do anything.

Then, they send another D-Mail which


   changes Akihabara drastically


and it is after this change that Okabe discovers that Ruka has changed.

I thought it was the latter D-Mail that caused Ruka to change because it was the D-Mail directly before the change was realized, when people started behaving as if Ruka was


   a girl all along.


However, when this latter D-Mail, which had an effect on the city,


   is cancelled out,


Ruka is still


   a girl.


Was it the former or latter D-Mail that caused Ruka to change?

Relevant episodes:

Episode 8


   D-Mail sent to change Ruka's gender. Likely a failure as it just told Ruka's mother to change her diet.


Episode 9


   Faris's unknown D-Mail which changes Akihabara.


Episode 10


   Okabe discovers Ruka's gender change, spurred by how people treat her as a girl.


Episode 17


   Okabe reverts Akihabara to its prior state.


Episode 18


   Okabe has to revert Ruka to a boy.
It was the D-Mail Ruka sent that changed Ruka to a girl. 

When Okabe sees Ruka, he doesn't realize Ruka has in fact become a girl. He only realizes after Faris' D-Mail that Ruka has become a girl.

Also to support this, Faris' D-Mail wasn't sent that long back to have affected Ruka's gender, as Ruka was born well before Faris' D-Mail was sent.