Class: StringIO

Inherits:
Data
  • Object
show all
Includes:
Enumerable
Defined in:
stringio.c

Class Method Summary collapse

Instance Method Summary collapse

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.

Yields:

  • (strio)


200
201
202
# File 'stringio.c', line 200

static VALUE
strio_s_open(argc, argv, klass)
int argc;

Instance Method Details

#<<Object

#binmodeObject

#each_byte {|byte| ... } ⇒ Object

See IO#each_byte.

Yields:

  • (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.

Yields:

  • (char)


817
818
819
# File 'stringio.c', line 817

static VALUE
strio_each_char(self)
VALUE self;

#closenil

Closes strio. The strio is unavailable for any further data operations; an IOError is raised if such an attempt is made.

Returns:

  • (nil)


393
394
395
# File 'stringio.c', line 393

static VALUE
strio_close(self)
VALUE self;

#close_readnil

Closes the read end of a StringIO. Will raise an IOError if the strio is not readable.

Returns:

  • (nil)


412
413
414
# File 'stringio.c', line 412

static VALUE
strio_close_read(self)
VALUE self;

#close_writenil

Closes the write end of a StringIO. Will raise an IOError if the strio is not writeable.

Returns:

  • (nil)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Overloads:

  • #each(sep_string = $/) {|line| ... } ⇒ Object

    Yields:

    • (line)
  • #each_line(sep_string = $/) {|line| ... } ⇒ Object

    Yields:

    • (line)


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.

Yields:

  • (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.

Yields:

  • (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.

Overloads:

  • #each(sep_string = $/) {|line| ... } ⇒ Object

    Yields:

    • (line)
  • #each_line(sep_string = $/) {|line| ... } ⇒ Object

    Yields:

    • (line)


1005
1006
1007
# File 'stringio.c', line 1005

static VALUE
strio_each(argc, argv, self)
int argc;

#eofBoolean #eof?Boolean

Returns true if strio is at end of file. The stringio must be opened for reading or an IOError will be raised.

Overloads:

  • #eofBoolean

    Returns:

    • (Boolean)
  • #eof?Boolean

    Returns:

    • (Boolean)


496
497
498
# File 'stringio.c', line 496

static VALUE
strio_eof(self)
VALUE self;

#eofBoolean #eof?Boolean

Returns true if strio is at end of file. The stringio must be opened for reading or an IOError will be raised.

Overloads:

  • #eofBoolean

    Returns:

    • (Boolean)
  • #eof?Boolean

    Returns:

    • (Boolean)


496
497
498
# File 'stringio.c', line 496

static VALUE
strio_eof(self)
VALUE self;

#fcntlObject

#filenoObject

#flushObject

#fsyncObject

#getcFixnum?

See IO#getc.

Returns:

  • (Fixnum, nil)


731
732
733
# File 'stringio.c', line 731

static VALUE
strio_getc(self)
VALUE self;

#getcFixnum?

See IO#getc.

Returns:

  • (Fixnum, nil)


731
732
733
# File 'stringio.c', line 731

static VALUE
strio_getc(self)
VALUE self;

#gets(sep_string = $/) ⇒ String?

See IO#gets.

Returns:

  • (String, nil)


969
970
971
# File 'stringio.c', line 969

static VALUE
strio_gets(argc, argv, self)
int argc;

#initialize_copyObject

:nodoc:



506
507
508
# File 'stringio.c', line 506

static VALUE
strio_copy(copy, orig)
VALUE copy, orig;

#isattyObject

#sizeInteger

Returns the size of the buffer string.

Returns:

  • (Integer)


1262
1263
1264
# File 'stringio.c', line 1262

static VALUE
strio_size(self)
VALUE self;

#linenoInteger

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.

Returns:

  • (Integer)


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.

Returns:

  • (Integer)


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.

Overloads:

  • #each(sep_string = $/) {|line| ... } ⇒ Object

    Yields:

    • (line)
  • #each_line(sep_string = $/) {|line| ... } ⇒ Object

    Yields:

    • (line)


1005
1006
1007
# File 'stringio.c', line 1005

static VALUE
strio_each(argc, argv, self)
int argc;

#pathObject

#pidObject

#posInteger #tellInteger

Returns the current offset (in bytes) of strio.

Overloads:

  • #posInteger

    Returns:

    • (Integer)
  • #tellInteger

    Returns:

    • (Integer)


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.

Returns:

  • (Integer)


610
611
612
# File 'stringio.c', line 610

static VALUE
strio_set_pos(self, pos)
VALUE self;

#printfObject

#putc(obj) ⇒ Object

See IO#putc.

Returns:

  • (Object)


1111
1112
1113
# File 'stringio.c', line 1111

static VALUE
strio_putc(self, ch)
VALUE self, ch;

#putsObject

#read([length [, buffer]]) ⇒ String?

See IO#read.

Returns:

  • (String, nil)


1144
1145
1146
# File 'stringio.c', line 1144

static VALUE
strio_read(argc, argv, self)
int argc;

#readcharFixnum

See IO#readchar.

Returns:

  • (Fixnum)


802
803
804
# File 'stringio.c', line 802

static VALUE
strio_readchar(self)
VALUE self;

#readcharFixnum

See IO#readchar.

Returns:

  • (Fixnum)


802
803
804
# File 'stringio.c', line 802

static VALUE
strio_readchar(self)
VALUE self;

#readline(sep_string = $/) ⇒ String

See IO#readline.

Returns:

  • (String)


987
988
989
# File 'stringio.c', line 987

static VALUE
strio_readline(argc, argv, self)
int argc;

#readlines(sep_string = $/) ⇒ Array

See IO#readlines.

Returns:

  • (Array)


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;

#rewind0

Positions strio to the beginning of input, resetting lineno to zero.

Returns:

  • (0)


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).

Returns:

  • (0)


650
651
652
# File 'stringio.c', line 650

static VALUE
strio_seek(argc, argv, self)
int argc;

#sizeInteger

Returns the size of the buffer string.

Returns:

  • (Integer)


1262
1263
1264
# File 'stringio.c', line 1262

static VALUE
strio_size(self)
VALUE self;

#stringString

Returns underlying String object, the subject of IO.

Returns:

  • (String)


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.

Returns:

  • (String)


371
372
373
# File 'stringio.c', line 371

static VALUE
strio_set_string(self, string)
VALUE self, string;

#synctrue

Returns true always.

Returns:

  • (true)


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.

Returns:

  • (String)


1224
1225
1226
# File 'stringio.c', line 1224

static VALUE
strio_sysread(argc, argv, self)
int argc;

#syswriteObject

#tellObject

#truncate(integer) ⇒ 0

Truncates the buffer string to at most integer bytes. The strio must be opened for writing.

Returns:

  • (0)


1280
1281
1282
# File 'stringio.c', line 1280

static VALUE
strio_truncate(self, len)
VALUE self, len;

#tty?Boolean

Returns:

  • (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.

Returns:

  • (nil)


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.

Overloads:

  • #write(string) ⇒ Integer

    Returns:

    • (Integer)
  • #syswrite(string) ⇒ Integer

    Returns:

    • (Integer)


1052
1053
1054
# File 'stringio.c', line 1052

static VALUE
strio_write(self, str)
VALUE self, str;