Method: String#getbyte

Defined in:
string.c

#getbyte(index) ⇒ 0 .. 255

returns the indexth byte as an integer.

Returns:

  • (0 .. 255)


4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
# File 'string.c', line 4841

static VALUE
rb_str_getbyte(VALUE str, VALUE index)
{
    long pos = NUM2LONG(index);

    if (pos < 0)
        pos += RSTRING_LEN(str);
    if (pos < 0 ||  RSTRING_LEN(str) <= pos)
        return Qnil;

    return INT2FIX((unsigned char)RSTRING_PTR(str)[pos]);
}