Repository URL to install this package:
|
Version:
2.2.2-1 ▾
|
U:RDoc::AnyMethod[iI"new:ETI"IO::new;TT:publico:RDoc::Markup::Document:@parts[7o:RDoc::Markup::Paragraph; [I"NReturns a new IO object (a stream) for the given integer file descriptor ;TI"P+fd+ and +mode+ string. +opt+ may be used to specify parts of +mode+ in a ;TI"?more readable fashion. See also IO.sysopen and IO.for_fd.;To:RDoc::Markup::BlankLine o;
; [I"OIO.new is called by various File and IO opening methods such as IO::open, ;TI"!Kernel#open, and File::open.;T@S:RDoc::Markup::Heading:
leveli: textI"Open Mode;T@o;
; [I"NWhen +mode+ is an integer it must be combination of the modes defined in ;TI"NFile::Constants (+File::RDONLY+, +File::WRONLY | File::CREAT+). See the ;TI"+open(2) man page for more information.;T@o;
; [I"FWhen +mode+ is a string it must be in one of the following forms:;T@o:RDoc::Markup::Verbatim; [ I"fmode
;TI"fmode ":" ext_enc
;TI"#fmode ":" ext_enc ":" int_enc
;TI"fmode ":" "BOM|UTF-*"
;T:@format0o;
; [I"O+fmode+ is an IO open mode string, +ext_enc+ is the external encoding for ;TI"3the IO and +int_enc+ is the internal encoding.;T@S;;
i ;I"IO Open Mode;T@o;
; [I"*Ruby allows the following open modes:;T@o;; [I"B"r" Read-only, starts at beginning of file (default mode).
;TI"
;TI"3"r+" Read-write, starts at beginning of file.
;TI"
;TI"."w" Write-only, truncates existing file
;TI"< to zero length or creates a new file for writing.
;TI"
;TI"="w+" Read-write, truncates existing file to zero length
;TI"9 or creates a new file for reading and writing.
;TI"
;TI"C"a" Write-only, each write call appends data at end of file.
;TI"A Creates a new file for writing if file does not exist.
;TI"
;TI"C"a+" Read-write, each write call appends data at end of file.
;TI"B Creates a new file for reading and writing if file does
;TI" not exist.
;T;0o;
; [I"PThe following modes must be used separately, and along with one or more of ;TI"the modes seen above.;T@o;; [I""b" Binary file mode
;TI"= Suppresses EOL <-> CRLF conversion on Windows. And
;TI"A sets external encoding to ASCII-8BIT unless explicitly
;TI" specified.
;TI"
;TI""t" Text file mode
;T;0o;
; [I"HWhen the open mode of original IO is read only, the mode cannot be ;TI"Nchanged to be writable. Similarly, the open mode cannot be changed from ;TI"write only to readable.;T@o;
; [I"PWhen such a change is attempted the error is raised in different locations ;TI"according to the platform.;T@S;;
i;I"IO Encoding;T@o;
; [I"NWhen +ext_enc+ is specified, strings read will be tagged by the encoding ;TI"Iwhen reading, and strings output will be converted to the specified ;TI"encoding when writing.;T@o;
; [ I"OWhen +ext_enc+ and +int_enc+ are specified read strings will be converted ;TI"Ifrom +ext_enc+ to +int_enc+ upon input, and written strings will be ;TI"Jconverted from +int_enc+ to +ext_enc+ upon output. See Encoding for ;TI"8further details of transcoding on input and output.;T@o;
; [I"PIf "BOM|UTF-8", "BOM|UTF-16LE" or "BOM|UTF16-BE" are used, ruby checks for ;TI"Na Unicode BOM in the input document to help determine the encoding. For ;TI"PUTF-16 encodings the file open mode must be binary. When present, the BOM ;TI"Ois stripped and the external encoding from the BOM is used. When the BOM ;TI"Ois missing the given Unicode encoding is used as +ext_enc+. (The BOM-set ;TI"Hencoding option is case insensitive, so "bom|utf-8" is also valid.);T@S;;
i;I"Options;T@o;
; [I"H+opt+ can be used instead of +mode+ for improved readability. The ;TI""following keys are supported:;T@o:RDoc::Markup::List:
@type: NOTE:@items[o:RDoc::Markup::ListItem:@label[I":mode ;T; [o;
; [I"Same as +mode+ parameter;T@o;;[I":\external_encoding ;T; [o;
; [I"NExternal encoding for the IO. "-" is a synonym for the default external ;TI"encoding.;T@o;;[I":\internal_encoding ;T; [ o;
; [I"NInternal encoding for the IO. "-" is a synonym for the default internal ;TI"encoding.;T@o;
; [I".If the value is nil no conversion occurs.;T@o;;[I":encoding ;T; [o;
; [I"BSpecifies external and internal encodings as "extern:intern".;T@o;;[I":textmode ;T; [o;
; [I"AIf the value is truth value, same as "t" in argument +mode+.;T@o;;[I":binmode ;T; [o;
; [I"AIf the value is truth value, same as "b" in argument +mode+.;T@o;;[I":autoclose ;T; [o;
; [I"GIf the value is +false+, the +fd+ will be kept open after this IO ;TI"instance gets finalized.;T@o;
; [I"PAlso, +opt+ can have same keys in String#encode for controlling conversion ;TI"=between the external encoding and the internal encoding.;T@S;;
i;I"Example 1;T@o;; [ I"&fd = IO.sysopen("/dev/tty", "w")
;TI"a = IO.new(fd,"w")
;TI"$stderr.puts "Hello"
;TI"a.puts "World"
;T;0o;
; [I"Produces:;T@o;; [I"Hello
;TI"World
;T;0S;;
i;I"Example 2;T@o;; [I"require 'fcntl'
;TI"
;TI"'fd = STDERR.fcntl(Fcntl::F_DUPFD)
;TI";io = IO.new(fd, mode: 'w:UTF-16LE', cr_newline: true)
;TI"io.puts "Hello, World!"
;TI"
;TI"'fd = STDERR.fcntl(Fcntl::F_DUPFD)
;TI"2io = IO.new(fd, mode: 'w', cr_newline: true,
;TI"8 external_encoding: Encoding::UTF_16LE)
;TI"io.puts "Hello, World!"
;T;0o;
; [I"NBoth of above print "Hello, World!" in UTF-16LE to standard error output ;TI">with converting EOL generated by <code>puts</code> to CR.;T:
@fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I")IO.new(fd [, mode] [, opt]) -> io
;T0[ I"(p1, p2 = v2, p3 = {});T@ÉFI"IO;TcRDoc::NormalClass00