Class: StringIO
Class Method Summary collapse
-
.open(string = ""[, mode]) {|strio| ... } ⇒ Object
Equivalent to StringIO.new except that when it is called with a block, it yields with the new instance and closes it, and returns the result which returned from the block.
Instance Method Summary collapse
- #<< ⇒ Object
- #binmode ⇒ Object
-
#close ⇒ nil
Closes strio.
-
#close_read ⇒ nil
Closes the read end of a StringIO.
-
#close_write ⇒ nil
Closes the write end of a StringIO.
-
#closed? ⇒ Boolean
Returns
trueif strio is completely closed,falseotherwise. -
#closed_read? ⇒ Boolean
Returns
trueif strio is not readable,falseotherwise. -
#closed_write? ⇒ Boolean
Returns
trueif strio is not writable,falseotherwise. -
#each ⇒ Object
See IO#each.
-
#each_byte {|byte| ... } ⇒ Object
See IO#each_byte.
-
#each_line ⇒ Object
See IO#each.
-
#eof ⇒ Object
Returns true if strio is at end of file.
-
#eof? ⇒ Object
Returns true if strio is at end of file.
- #fcntl ⇒ Object
- #fileno ⇒ Object
- #flush ⇒ Object
- #fsync ⇒ Object
-
#getc ⇒ Fixnum?
See IO#getc.
-
#gets(sep_string = $/) ⇒ String?
See IO#gets.
-
#new(string = ""[, mode]) ⇒ Object
constructor
Creates new StringIO instance from with string and mode.
-
#initialize_copy ⇒ Object
:nodoc:.
- #isatty ⇒ Object
-
#size ⇒ Integer
Returns the size of the buffer string.
-
#lineno ⇒ Integer
Returns the current line number in strio.
-
#lineno=(integer) ⇒ Integer
Manually sets the current line number to the given value.
- #path ⇒ Object
- #pid ⇒ Object
-
#pos ⇒ Object
Returns the current offset (in bytes) of strio.
-
#pos=(integer) ⇒ Integer
Seeks to the given position (in bytes) in strio.
- #print ⇒ Object
- #printf ⇒ Object
-
#putc(obj) ⇒ Object
See IO#putc.
- #puts ⇒ Object
-
#read([length [, buffer]]) ⇒ String?
See IO#read.
-
#readchar ⇒ Fixnum
See IO#readchar.
-
#readline(sep_string = $/) ⇒ String
See IO#readline.
-
#readlines(sep_string = $/) ⇒ Array
See IO#readlines.
-
#reopen ⇒ Object
Reinitializes strio with the given other_StrIO or string and mode (see StringIO#new).
-
#rewind ⇒ 0
Positions strio to the beginning of input, resetting
linenoto zero. -
#seek(amount, whence = SEEK_SET) ⇒ 0
Seeks to a given offset amount in the stream according to the value of whence (see IO#seek).
-
#size ⇒ Integer
Returns the size of the buffer string.
-
#string ⇒ String
Returns underlying String object, the subject of IO.
-
#string=(string) ⇒ String
Changes underlying String object, the subject of IO.
-
#sync ⇒ true
Returns
truealways. - #sync= ⇒ Object
-
#sysread(integer[, outbuf]) ⇒ String
Similar to #read, but raises
EOFErrorat end of string instead of returningnil, as well as IO#sysread does. - #syswrite ⇒ Object
- #tell ⇒ Object
-
#truncate(integer) ⇒ 0
Truncates the buffer string to at most integer bytes.
- #tty? ⇒ Boolean
-
#ungetc(integer) ⇒ nil
Pushes back one character (passed as a parameter) onto strio such that a subsequent buffered read will return it.
-
#write ⇒ Object
Appends the given string to the underlying buffer string of strio.
Constructor Details
#new(string = ""[, mode]) ⇒ Object
Creates new StringIO instance from with string and mode.
213 214 215 |
# File 'stringio.c', line 213 static VALUE strio_initialize(argc, argv, self) int argc; |
Class Method Details
.open(string = ""[, mode]) {|strio| ... } ⇒ Object
Equivalent to StringIO.new except that when it is called with a block, it yields with the new instance and closes it, and returns the result which returned from the block.
197 198 199 |
# File 'stringio.c', line 197 static VALUE strio_s_open(argc, argv, klass) int argc; |
Instance Method Details
#<< ⇒ Object
#binmode ⇒ Object
#close ⇒ nil
Closes strio. The strio is unavailable for any further data operations; an IOError is raised if such an attempt is made.
380 381 382 |
# File 'stringio.c', line 380 static VALUE strio_close(self) VALUE self; |
#close_read ⇒ nil
Closes the read end of a StringIO. Will raise an IOError if the strio is not readable.
399 400 401 |
# File 'stringio.c', line 399 static VALUE strio_close_read(self) VALUE self; |
#close_write ⇒ nil
Closes the write end of a StringIO. Will raise an IOError if the strio is not writeable.
418 419 420 |
# File 'stringio.c', line 418 static VALUE strio_close_write(self) VALUE self; |
#closed? ⇒ Boolean
Returns true if strio is completely closed, false otherwise.
436 437 438 |
# File 'stringio.c', line 436 static VALUE strio_closed(self) VALUE self; |
#closed_read? ⇒ Boolean
Returns true if strio is not readable, false otherwise.
451 452 453 |
# File 'stringio.c', line 451 static VALUE strio_closed_read(self) VALUE self; |
#closed_write? ⇒ Boolean
Returns true if strio is not writable, false otherwise.
466 467 468 |
# File 'stringio.c', line 466 static VALUE strio_closed_write(self) VALUE self; |
#each(sep_string = $/) {|line| ... } ⇒ Object #each_line(sep_string = $/) {|line| ... } ⇒ Object
See IO#each.
950 951 952 |
# File 'stringio.c', line 950 static VALUE strio_each(argc, argv, self) int argc; |
#each_byte {|byte| ... } ⇒ Object
See IO#each_byte.
693 694 695 |
# File 'stringio.c', line 693 static VALUE strio_each_byte(self) VALUE self; |
#each(sep_string = $/) {|line| ... } ⇒ Object #each_line(sep_string = $/) {|line| ... } ⇒ Object
See IO#each.
950 951 952 |
# File 'stringio.c', line 950 static VALUE strio_each(argc, argv, self) int argc; |
#eof ⇒ Boolean #eof? ⇒ Boolean
Returns true if strio is at end of file. The stringio must be opened for reading or an IOError will be raised.
483 484 485 |
# File 'stringio.c', line 483 static VALUE strio_eof(self) VALUE self; |
#eof ⇒ Boolean #eof? ⇒ Boolean
Returns true if strio is at end of file. The stringio must be opened for reading or an IOError will be raised.
483 484 485 |
# File 'stringio.c', line 483 static VALUE strio_eof(self) VALUE self; |
#fcntl ⇒ Object
#fileno ⇒ Object
#flush ⇒ Object
#fsync ⇒ Object
#getc ⇒ Fixnum?
See IO#getc.
711 712 713 |
# File 'stringio.c', line 711 static VALUE strio_getc(self) VALUE self; |
#gets(sep_string = $/) ⇒ String?
See IO#gets.
914 915 916 |
# File 'stringio.c', line 914 static VALUE strio_gets(argc, argv, self) int argc; |
#initialize_copy ⇒ Object
:nodoc:
493 494 495 |
# File 'stringio.c', line 493 static VALUE strio_copy(copy, orig) VALUE copy, orig; |
#isatty ⇒ Object
#size ⇒ Integer
Returns the size of the buffer string.
1205 1206 1207 |
# File 'stringio.c', line 1205 static VALUE strio_size(self) VALUE self; |
#lineno ⇒ Integer
Returns the current line number in strio. The stringio must be opened for reading. lineno counts the number of times gets is called, rather than the number of newlines encountered. The two values will differ if gets is called with a separator other than newline. See also the $. variable.
521 522 523 |
# File 'stringio.c', line 521 static VALUE strio_get_lineno(self) VALUE self; |
#lineno=(integer) ⇒ Integer
Manually sets the current line number to the given value. $. is updated only on the next read.
535 536 537 |
# File 'stringio.c', line 535 static VALUE strio_set_lineno(self, lineno) VALUE self, lineno; |
#path ⇒ Object
#pid ⇒ Object
#pos ⇒ Integer #tell ⇒ Integer
Returns the current offset (in bytes) of strio.
583 584 585 |
# File 'stringio.c', line 583 static VALUE strio_get_pos(self) VALUE self; |
#pos=(integer) ⇒ Integer
Seeks to the given position (in bytes) in strio.
596 597 598 |
# File 'stringio.c', line 596 static VALUE strio_set_pos(self, pos) VALUE self; |
#print ⇒ Object
#printf ⇒ Object
#putc(obj) ⇒ Object
See IO#putc.
1054 1055 1056 |
# File 'stringio.c', line 1054 static VALUE strio_putc(self, ch) VALUE self, ch; |
#puts ⇒ Object
#read([length [, buffer]]) ⇒ String?
See IO#read.
1087 1088 1089 |
# File 'stringio.c', line 1087 static VALUE strio_read(argc, argv, self) int argc; |
#readchar ⇒ Fixnum
See IO#readchar.
782 783 784 |
# File 'stringio.c', line 782 static VALUE strio_readchar(self) VALUE self; |
#readline(sep_string = $/) ⇒ String
See IO#readline.
932 933 934 |
# File 'stringio.c', line 932 static VALUE strio_readline(argc, argv, self) int argc; |
#readlines(sep_string = $/) ⇒ Array
See IO#readlines.
971 972 973 |
# File 'stringio.c', line 971 static VALUE strio_readlines(argc, argv, self) int argc; |
#reopen(other_StrIO) ⇒ Object #reopen(string, mode) ⇒ Object
Reinitializes strio with the given other_StrIO or string and mode (see StringIO#new).
563 564 565 |
# File 'stringio.c', line 563 static VALUE strio_reopen(argc, argv, self) int argc; |
#rewind ⇒ 0
Positions strio to the beginning of input, resetting lineno to zero.
618 619 620 |
# File 'stringio.c', line 618 static VALUE strio_rewind(self) VALUE self; |
#seek(amount, whence = SEEK_SET) ⇒ 0
Seeks to a given offset amount in the stream according to the value of whence (see IO#seek).
636 637 638 |
# File 'stringio.c', line 636 static VALUE strio_seek(argc, argv, self) int argc; |
#size ⇒ Integer
Returns the size of the buffer string.
1205 1206 1207 |
# File 'stringio.c', line 1205 static VALUE strio_size(self) VALUE self; |
#string ⇒ String
Returns underlying String object, the subject of IO.
345 346 347 |
# File 'stringio.c', line 345 static VALUE strio_get_string(self) VALUE self; |
#string=(string) ⇒ String
Changes underlying String object, the subject of IO.
358 359 360 |
# File 'stringio.c', line 358 static VALUE strio_set_string(self, string) VALUE self, string; |
#sync ⇒ true
Returns true always.
674 675 676 |
# File 'stringio.c', line 674 static VALUE strio_get_sync(self) VALUE self; |
#sync= ⇒ Object
#sysread(integer[, outbuf]) ⇒ String
Similar to #read, but raises EOFError at end of string instead of returning nil, as well as IO#sysread does.
1167 1168 1169 |
# File 'stringio.c', line 1167 static VALUE strio_sysread(argc, argv, self) int argc; |
#syswrite ⇒ Object
#tell ⇒ Object
#truncate(integer) ⇒ 0
Truncates the buffer string to at most integer bytes. The strio must be opened for writing.
1223 1224 1225 |
# File 'stringio.c', line 1223 static VALUE strio_truncate(self, len) VALUE self, len; |
#tty? ⇒ Boolean
#ungetc(integer) ⇒ nil
Pushes back one character (passed as a parameter) onto strio such that a subsequent buffered read will return it. Pushing back behind the beginning of the buffer string is not possible. Nothing will be done if such an attempt is made. In other case, there is no limitation for multiple pushbacks.
754 755 756 |
# File 'stringio.c', line 754 static VALUE strio_ungetc(self, ch) VALUE self, ch; |
#write(string) ⇒ Integer #syswrite(string) ⇒ Integer
Appends the given string to the underlying buffer string of strio. The stream must be opened for writing. If the argument is not a string, it will be converted to a string using to_s. Returns the number of bytes written. See IO#write.
995 996 997 |
# File 'stringio.c', line 995 static VALUE strio_write(self, str) VALUE self, str; |