コード例 #1
0
    void RubyEvaluator::ContextToGlobal(VALUE ctx, KObjectRef o)
    {
        if (global_object.isNull())
            return;

        // Next copy all methods over -- they override variables
        VALUE methods = rb_funcall(ctx, rb_intern("singleton_methods"), 0);
        for (long i = 0; i < RARRAY_LEN(methods); i++)
        {
            VALUE meth_symbol = rb_ary_entry(methods, i);
            const char* meth_name = STR2CSTR(meth_symbol);

            // Skip our special method_missing method
            if (strcmp(meth_name, "method_missing") == 0)
                continue;

            volatile VALUE rmeth = rb_funcall(ctx, rb_intern("method"), 1, meth_symbol);
            KMethodRef method = new KRubyMethod(rmeth, meth_name);
            o->SetMethod(meth_name, method);
        }
    }