Ruby IO#read/write cheat sheet

Posted by Yoshimasa Niwa on 03/09, 2007

Ruby has many read/write method for IO classes. For instance, Socket class has more than 10 read method; getc, gets, read, readchar, readline, readlines, read nonblock, readpartial, sysread, recv, and recv noblock. When we use Socket class, for example write a program with network connection via TCPSocket and TCPServer, we confuse which read/write method is best for the code.

All IO#read/write methods are unique and different each other. In fact, ether readchar or getc reads one char but, readchar throw EOFError when reach the eod of file or stream.

This cheat sheet shows which method throw exceptions, block while read/write completes or how length it read, in table.

Let cheat it!

Download

rubyioreadwritemethods.pdf

Share

Comments

Your name
Your email
(optional)
Your url
(optional)
Your comment