IO Flashcards
Input Output in Ruby
STDIN
standard input, gets info explicity from user ex. STDIN.gets.chomp()
r
Read-only, starts at beginning of file (default mode).
r+
Read-write, starts at beginning of file.
w
Write-only, truncates existing file to zero length or creates a new file for writing.
w+
Read-write, truncates existing file to zero length or creates a new file for reading and writing.
a
Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
a+
Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
b
Binary file mode (may appear with any of the key letters listed). Suppresses EOL CRLF conversion on Windows. And sets external encoding to ASCII-8BIT unless explicitly specified.
t
Text file mode (may appear with any of the key letters listed except “b”).
seek
method class of IO, moves the file pointer to a given integer distance(first parameter) in the stream according to the value of the second parameter in the seek method ex. def rewind(f) f.seek(0, IO::SEEK_SET) end
IO::SEEK_CUR
Seeks to first integer number parameter plus current position
IO::SEEK_END
Seeks to first integer number parameter plus end of stream (you probably want a negative value for first integer number parameter)
IO::SEEK_SET
Seeks to the absolute location given by first integer number parameter