Ruby 2.4

RubyVM

RubyVM类

Parent:Object

::RubyVM

常量

DEFAULT_PARAMS

DEFAULT_PARAMS此常数变量显示VM的默认参数。请注意,更改这些值不会影响VM的执行。规格不稳定,你不应该依赖这个值。当然,这个常数是MRI特定的。

INSTRUCTION_NAMES

INSTRUCTION_NAMES

OPTS

OPTS,它显示vm构建选项

公共类方法

stat → Hash Show source

stat(hsh) → hsh

stat(Symbol) → Numeric

返回虚拟机中包含依赖于实现的计数器的哈希。

此散列包含有关方法/常量高速缓存序列的信息:

{ :global_method_state=>251, :global_constant_state=>481, :class_serial=>9029 }

散列的内容是特定于实现的,将来可能会更改。

此方法仅适用于C Ruby。

static VALUE vm_stat(int argc, VALUE *argv, VALUE self) { static VALUE sym_global_method_state, sym_global_constant_state, sym_class_serial; VALUE arg = Qnil; VALUE hash = Qnil, key = Qnil; if (rb_scan_args(argc, argv, "01", &arg) == 1) { 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_method_state == 0) { #define S(s) sym_##s = ID2SYM(rb_intern_const(#s)) S(global_method_state S(global_constant_state S(class_serial #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_method_state, ruby_vm_global_method_state SET(global_constant_state, ruby_vm_global_constant_state SET(class_serial, ruby_vm_class_serial #undef SET if (!NIL_P(key)) { /* matched key should return above */ rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key) } return hash; }