ruby - Can objects made with c extensions instantiate and manage each other? -
right have series of objects created using c extensions,
- foo
- bar
- baz.
i have ruby code instantiates 3 of them, calls functions , processed results. let's call that:
- manager
well, manager bottleneck, i'd turn c extension. don't know how instantiate foo, bar, , baz within manager. have use code like:
value module_klass = rb_const_get(rb_cobject, rb_intern("module")); value object_klass = rb_const_get(module_klass, rb_intern("foo"));
and call methods like:
rb_funcall(object_klass, rb_intern("new"), 0);
or there cleaner way?
check out rb_class_new_instance()
. like:
value module_klass = rb_const_get(rb_cobject, rb_intern("module")); value foo_klass = rb_const_get(module_klass, rb_intern("foo")); value foo = rb_class_new_instance(0, null, foo_klass); value data = rb_funcall(foo, rb_intern("some_foo_method"), ...);
Comments
Post a Comment