What you are trying to do is execute a program from a memory location.
I don't know how ruby does it (meterpreter is written in C, perhaps C++ if my SVN logs are correct), but doing it via a C call is "CreateProcess" and pointing the file pointer at a memory location - or something very similar.
Side Note: A lot of people immediately assume viral intent when you write one of these, be careful where you start googling this information!


