I'm currently trying to get all the instances of a class and I wanted to use ObjectSpace.each_object to achieve that.
Here is my actual code in C :
ruby_init();
int ruby_state = 0;
rb_string_eval_protect("def my_func ; ObjectSpace.each_object(Klass) { |x| x.do_something } ; end", &ruby_state);
ruby_cleanup(ruby_state);
However, I don't know if it's really a good thing to do. I wanted to use rb_funcall instead, which is maybe a cleaner way to do it.
My questions are :
- Is it better to use
rb_funcallthanstring_eval? (I think so because of parser) - How can I retrieve the
ObjectSpacemodule in C API sincerb_mObjectSpacedoesn't seem to exist?