End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
RubyVM.stat
RubyVM.stat → Hash
RubyVM.stat(hsh) → hsh
RubyVM.stat(Symbol) → Numeric
vm.c
View on GitHub ↗
static VALUE
vm_stat(int argc, VALUE *argv, VALUE self)
{
static VALUE sym_global_constant_state, sym_class_serial, sym_global_cvar_state;
VALUE arg = Qnil;
VALUE hash = Qnil, key = Qnil;
if (rb_check_arity(argc, 0, 1) == 1) {
arg = argv[0];
if (SYMBOL_P(arg))
key = arg;
else if (RB_TYPE_P(arg, T_HASH))
hash = arg;
else
rb_raise(rb_eTypeError, "non-hash or symbol given");
}
else {
hash = rb_hash_new();
}
if (sym_global_constant_state == 0) {
#define S(s) sym_##s = ID2SYM(rb_intern_const(#s))
S(global_constant_state);
S(class_serial);
S(global_cvar_state);
#undef S
}
#define SET(name, attr) \
if (key == sym_##name) \
return SERIALT2NUM(attr); \
else if (hash != Qnil) \
rb_hash_aset(hash, sym_##name, SERIALT2NUM(attr));
SET(global_constant_state, ruby_vm_global_constant_state);
SET(class_serial, ruby_vm_class_serial);
SET(global_cvar_state, ruby_vm_global_cvar_state);
#undef SET
if (!NIL_P(key)) { /* matched key should return above */
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
}
return hash;
}
Returns a Hash containing implementation-dependent counters inside the VM.
This hash includes information about method/constant cache serials:
Example
{
:global_constant_state=>481,
:class_serial=>9029
}
The contents of the hash are implementation specific and may be changed in the future.
This method is only expected to work on C Ruby.