End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO::Buffer#values
values(data_type, [offset, [count]]) → array
io_buffer.c
View on GitHub ↗
static VALUE
io_buffer_values(int argc, VALUE *argv, VALUE self)
{
const void *base;
size_t size;
rb_io_buffer_get_bytes_for_reading(self, &base, &size);
ID data_type;
if (argc >= 1) {
data_type = RB_SYM2ID(argv[0]);
} else {
data_type = RB_IO_BUFFER_DATA_TYPE_U8;
}
size_t offset;
if (argc >= 2) {
offset = NUM2SIZET(argv[1]);
} else {
offset = 0;
}
size_t count;
if (argc >= 3) {
count = NUM2SIZET(argv[2]);
} else {
count = (size - offset) / io_buffer_data_type_size(data_type);
}
VALUE array = rb_ary_new_capa(count);
for (size_t i = 0; i < count; i++) {
VALUE value = rb_io_buffer_get_value(base, size, data_type, &offset);
rb_ary_push(array, value);
}
return array;
}
Returns an array of values of data_type starting from offset.
If count is given, only count values will be returned.
Example:
Example
IO::Buffer.for("Hello World").values(:U8, 2, 2) # => [108, 108]