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
-
#each_byte {|byte| ... } ⇒ Object
See IO#each_byte.
-
#each_char {|char| ... } ⇒ Object
See IO#each_char.
-
#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_char {|char| ... } ⇒ Object
See IO#each_char.
-
#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.
-
#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.
-
#lines ⇒ Object
See IO#each.
- #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.
-
#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.
216 217 218 |
# File 'stringio.c', line 216 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.
200 201 202 |
# File 'stringio.c', line 200 static VALUE strio_s_open(argc, argv, klass) int argc; |
Instance Method Details
#<< ⇒ Object
#binmode ⇒ Object
#each_byte {|byte| ... } ⇒ Object
See IO#each_byte.
710 711 712 |
# File 'stringio.c', line 710 static VALUE strio_each_byte(self) VALUE self; |
#each_char {|char| ... } ⇒ Object
See IO#each_char.
817 818 819 |
# File 'stringio.c', line 817 static VALUE strio_each_char(self) VALUE self; |
#close ⇒ nil
Closes strio. The strio is unavailable for any further data operations; an IOError is raised if such an attempt is made.
393 394 395 |
# File 'stringio.c', line 393 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.
412 413 414 |
# File 'stringio.c', line 412 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.
431 432 433 |
# File 'stringio.c', line 431 static VALUE strio_close_write(self) VALUE self; |
#closed? ⇒ Boolean
Returns true if strio is completely closed, false otherwise.
449 450 451 |
# File 'stringio.c', line 449 static VALUE strio_closed(self) VALUE self; |
#closed_read? ⇒ Boolean
Returns true if strio is not readable, false otherwise.
464 465 466 |
# File 'stringio.c', line 464 static VALUE strio_closed_read(self) VALUE self; |
#closed_write? ⇒ Boolean
Returns true if strio is not writable, false otherwise.
479 480 481 |
# File 'stringio.c', line 479 static VALUE strio_closed_write(self) VALUE self; |
#each(sep_string = $/) {|line| ... } ⇒ Object #each_line(sep_string = $/) {|line| ... } ⇒ Object
See IO#each.
1005 1006 1007 |
# File 'stringio.c', line 1005 static VALUE strio_each(argc, argv, self) int argc; |
#each_byte {|byte| ... } ⇒ Object
See IO#each_byte.
710 711 712 |
# File 'stringio.c', line 710 static VALUE strio_each_byte(self) VALUE self; |
#each_char {|char| ... } ⇒ Object
See IO#each_char.
817 818 819 |
# File 'stringio.c', line 817 static VALUE strio_each_char(self) VALUE self; |
#each(sep_string = $/) {|line| ... } ⇒ Object #each_line(sep_string = $/) {|line| ... } ⇒ Object
See IO#each.
1005 1006 1007 |
# File 'stringio.c', line 1005 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.
496 497 498 |
# File 'stringio.c', line 496 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.
496 497 498 |
# File 'stringio.c', line 496 static VALUE strio_eof(self) VALUE self; |
#fcntl ⇒ Object
#fileno ⇒ Object
#flush ⇒ Object
#fsync ⇒ Object
#getc ⇒ Fixnum?
See IO#getc.
731 732 733 |
# File 'stringio.c', line 731 static VALUE strio_getc(self) VALUE self; |
#getc ⇒ Fixnum?
See IO#getc.
731 732 733 |
# File 'stringio.c', line 731 static VALUE strio_getc(self) VALUE self; |
#gets(sep_string = $/) ⇒ String?
See IO#gets.
969 970 971 |
# File 'stringio.c', line 969 static VALUE strio_gets(argc, argv, self) int argc; |
#initialize_copy ⇒ Object
:nodoc:
506 507 508 |
# File 'stringio.c', line 506 static VALUE strio_copy(copy, orig) VALUE copy, orig; |
#isatty ⇒ Object
#size ⇒ Integer
Returns the size of the buffer string.
1262 1263 1264 |
# File 'stringio.c', line 1262 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.
534 535 536 |
# File 'stringio.c', line 534 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.
548 549 550 |
# File 'stringio.c', line 548 static VALUE strio_set_lineno(self, lineno) VALUE self, lineno; |
#each(sep_string = $/) {|line| ... } ⇒ Object #each_line(sep_string = $/) {|line| ... } ⇒ Object
See IO#each.
1005 1006 1007 |
# File 'stringio.c', line 1005 static VALUE strio_each(argc, argv, self) int argc; |
#path ⇒ Object
#pid ⇒ Object
#pos ⇒ Integer #tell ⇒ Integer
Returns the current offset (in bytes) of strio.
597 598 599 |
# File 'stringio.c', line 597 static VALUE strio_get_pos(self) VALUE self; |
#pos=(integer) ⇒ Integer
Seeks to the given position (in bytes) in strio.
610 611 612 |
# File 'stringio.c', line 610 static VALUE strio_set_pos(self, pos) VALUE self; |
#print ⇒ Object
#printf ⇒ Object
#putc(obj) ⇒ Object
See IO#putc.
1111 1112 1113 |
# File 'stringio.c', line 1111 static VALUE strio_putc(self, ch) VALUE self, ch; |
#puts ⇒ Object
#read([length [, buffer]]) ⇒ String?
See IO#read.
1144 1145 1146 |
# File 'stringio.c', line 1144 static VALUE strio_read(argc, argv, self) int argc; |
#readchar ⇒ Fixnum
See IO#readchar.
802 803 804 |
# File 'stringio.c', line 802 static VALUE strio_readchar(self) VALUE self; |
#readchar ⇒ Fixnum
See IO#readchar.
802 803 804 |
# File 'stringio.c', line 802 static VALUE strio_readchar(self) VALUE self; |
#readline(sep_string = $/) ⇒ String
See IO#readline.
987 988 989 |
# File 'stringio.c', line 987 static VALUE strio_readline(argc, argv, self) int argc; |
#readlines(sep_string = $/) ⇒ Array
See IO#readlines.
1028 1029 1030 |
# File 'stringio.c', line 1028 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).
576 577 578 |
# File 'stringio.c', line 576 static VALUE strio_reopen(argc, argv, self) int argc; |
#rewind ⇒ 0
Positions strio to the beginning of input, resetting lineno to zero.
632 633 634 |
# File 'stringio.c', line 632 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).
650 651 652 |
# File 'stringio.c', line 650 static VALUE strio_seek(argc, argv, self) int argc; |
#size ⇒ Integer
Returns the size of the buffer string.
1262 1263 1264 |
# File 'stringio.c', line 1262 static VALUE strio_size(self) VALUE self; |
#string ⇒ String
Returns underlying String object, the subject of IO.
358 359 360 |
# File 'stringio.c', line 358 static VALUE strio_get_string(self) VALUE self; |
#string=(string) ⇒ String
Changes underlying String object, the subject of IO.
371 372 373 |
# File 'stringio.c', line 371 static VALUE strio_set_string(self, string) VALUE self, string; |
#sync ⇒ true
Returns true always.
691 692 693 |
# File 'stringio.c', line 691 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.
1224 1225 1226 |
# File 'stringio.c', line 1224 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.
1280 1281 1282 |
# File 'stringio.c', line 1280 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.
774 775 776 |
# File 'stringio.c', line 774 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.
1052 1053 1054 |
# File 'stringio.c', line 1052 static VALUE strio_write(self, str) VALUE self, str; |