change write method to be compatible with ruby 1.9.1