Ruby/File Directory/IO.new
Материал из Wiki.crossplatform.ru
I/O modes
Mode Description r Read-only. Starts at the beginning of the file (default mode). r+ Read-write. Starts at the beginning of the 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 the end of file if the file exists, otherwise creates a new file for writing. a+ Read-write. Starts at the end of the file if the file exists, otherwise creates a new file for reading and writing. b (DOS/Windows only.) Binary file mode. May appear with any of the modes listed in this table.
Standard streams
Stream description File descriptor Predefined Ruby variable Ruby environment variable Standard input stream 0 $stdin STDIN Standard output stream 1 $stdout STDOUT Standard error output stream 2 $stderr STDERR
To create a new I/O stream named ios, use the new method.
# The first argument is 1, which is the numeric file descriptor for standard input. # Standard input can also be represented by the predefined Ruby variable $stdin. # The optional second argument, w, is a mode string meaning "write." ios = IO.new( 1, "w" ) ios.puts "IO, IO, it"s off to the computer lab I go." $stdout.puts "Do you copy?"