Fix issue 2113 StringIO puts printing nil

I've had a go at fixing issue #2113. I'm new here, let me know if I got anything wrong and I can change it.