Method: StringIO#each_byte

Defined in:
ext/stringio/stringio.c

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

With a block given, calls the block with each remaining byte in the stream; see Byte IO.

With no block given, returns an enumerator.

Yields:

  • (byte)

Returns:

  • (self)


843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'ext/stringio/stringio.c', line 843

static VALUE
strio_each_byte(VALUE self)
{
    struct StringIO *ptr;

    RETURN_ENUMERATOR(self, 0, 0);

    while ((ptr = strio_to_read(self)) != NULL) {
	char c = RSTRING_PTR(ptr->string)[ptr->pos++];
	rb_yield(CHR2FIX(c));
    }
    return self;
}