End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Integer#size
int.size → int
numeric.c
View on GitHub ↗
static VALUE
int_size(VALUE num)
{
if (FIXNUM_P(num)) {
return fix_size(num);
}
else if (RB_TYPE_P(num, T_BIGNUM)) {
return rb_big_size_m(num);
}
return Qnil;
}
Returns the number of bytes in the machine representation of int (machine dependent).
Example
1.size #=> 8 -1.size #=> 8 2147483647.size #=> 8 (256**10 - 1).size #=> 10 (256**20 - 1).size #=> 20 (256**40 - 1).size #=> 40