Hello,
Your problem with
ruby -e "$a=3"
and therefore also with
ruby -e "$stdout = StringIO.new".
Regardless of whether this makes sense, you have a problem with the shell
(or perhaps other command line interpreter). You are using an unprotected
ruby command text with characters that the shell interprets for itself.
With:
ruby -e '$a=3'
or
ruby -e "\$a=3"
no one complains anymore.