How to get a “separate” character in the Ruby C extension API

I want to return some values ​​from function C, and IMHO is a good option. I first used rb_intern('A_KEY') to create the keys, but the extension crashed. Now I use rb_str_new2 , but I prefer characters.

How to create a new character and use it without invoking a class or method?

+6
c ruby symbol ruby-c-extension
source share
1 answer

You need to use the ID2SYM macro to convert the identifier you get from rb_intern into a ruby ​​character. Try to change

 rb_intern('A_KEY') 

to

 ID2SYM(rb_intern('A_KEY')) 
+7
source share

All Articles