Can someone please guide me to get the key/value pairs in C
You use functions rb_hash_foreach, rb_hash_aref and friends. I believe
the best thing to do to learn how to use this function is to look at
the many examples in the MRI source code - especially in the
/On C side*/
VALUE func (VALUE self, VALUE obj)
/SAY if self corresponds to object of class AA/
VALUE test = rb_iv_get(self, “@Anchor”);
ID id = rb_intern(“anchorAA”);
VALUE test1 = rb_hash_aref(test, ID2SYM(id));
Is the above correct Carlo?
“@Anchor” means nothing. Anchor is a class constant, not an instance
The function to access class constants from C is rb_const_get. Search
for examples in the same way.
I personally never needed to access ruby class constants from C. I try
to make as neat a separation between the two worlds as possible. I use
C only when I need raw speed, or when I have to access C libraries.
If I were you, I’d pass all info I need to transfer from Ruby to C as
separate parameters. It is nifty to be ruby=ish under C, but it
obfuscates things a lot.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.