开发者

How I retrieve a 'standalone' symbol on Ruby's C extension API

开发者 https://www.devze.com 2023-01-31 22:06 出处:网络
I want to return several values from a C function, and IMHO, a hash is a good option. I first used rb_intern(\'A_KEY\') to create the keys, but the extension crashed. Now, I am using rb_str_new2, but

I want to return several values from a C function, and IMHO, a hash is a good option. I first used rb_intern('A_KEY') to create the keys, but the extension crashed. Now, I am using rb_str_new2, but I prefer symbols.

H开发者_开发问答ow do I create a new symbol, and use it without referring to a class or a method?


You need to use the ID2SYM macro to convert the identifier that you get from rb_intern into a ruby symbol. Try changing

rb_intern('A_KEY')

to

ID2SYM(rb_intern('A_KEY'))
0

精彩评论

暂无评论...
验证码 换一张
取 消