In 2006 I wrote a couple MIDI code generators for Ruby. The cooler of the two I unfortunately lost to the mists of time; it could generate simple ambient soundscapes in Reason. The more experimental one, v0.0.1, I put on my old Web site, gilesgoatboy.org, which still houses a lot of my art, video, and music.
Topher Cyll's mind-bogglingly cool Ruby book contains code to drive Pete Yandell's SimpleSynth with Ruby, but if you want to drive Reason instead, it's really easy. Assuming you're on OS X, download MIDI Patchbay, also by Pete Yandell. Then just set up a blank MIDI input and a blank MIDI output.
Next you'll want to set up something equally basic in Reason. Go into Preferences, and in Advanced MIDI, select the output bus you just created in MIDI Patchbay. Make sure you've got some kind of actual instrument plugged into a sound output in Reason - usually this'll happen if you just create a Subtractor synth - and in the Hardware Interface wire up MIDI channel 1 to your actual sound-making instrument.
Voila. You can now make music in Reason by generating MIDI in Ruby.