more functional ruby port

A working version of the ruby port.