A while ago, in a fit of defmacro-envy, I wrote a preprocessor that would let you wrap Python snippets in #python/#endpython blocks: http://codepad.org/5B388Wsh. This lets you write silly things like http://codepad.org/eS443WPA. I bet the same idea isn't too hard to implement in Ruby, but I don't know enough to try it myself.
I never really used it much - generating C code with Python print statements turned out to look uglier than I thought it would, and most of my use cases were better handled with X macros (https://en.wikipedia.org/wiki/X_Macro) or by generating a separate file and #include'ing it. But your description reminded me of it; you might like the idea.