Hi, I do know how to create a hash from C in wich keys and values are strings:
VALUE hash = rb_hash_new();
rb_hash_aset(hash, rb_str_new("mykey",5), rb_str_new2(myvalue));
But now I want to create Hash entries with Symbol keys so the resulting Hash
would look like:
{ :mykey => "lalala" }
By reading the C API documentation I don't find how to do it:
http://www.eqqon.com/index.php/Ruby_C_Extension
Any help please? Thanks a lot.
···
--
Iñaki Baz Castillo <ibc@aliax.net>
ops, solved right now:
rb_hash_aset(hash, ID2SYM( rb_intern("mykey") ), rb_str_new2(myvalue));
···
El Miércoles, 21 de Octubre de 2009, Iñaki Baz Castillo escribió:
Hi, I do know how to create a hash from C in wich keys and values are
strings:
VALUE hash = rb_hash_new();
rb_hash_aset(hash, rb_str_new("mykey",5), rb_str_new2(myvalue));
But now I want to create Hash entries with Symbol keys so the resulting
Hash would look like:
{ :mykey => "lalala" }
--
Iñaki Baz Castillo <ibc@aliax.net>
This should do it.....
rb_hash_aset(hash, ID2SYM(rb_intern("mykey")), rb_str_new2(myvalue));
John
···
On Tue, Oct 20, 2009 at 4:54 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
Hi, I do know how to create a hash from C in wich keys and values are
strings:
VALUE hash = rb_hash_new();
rb_hash_aset(hash, rb_str_new("mykey",5), rb_str_new2(myvalue));
But now I want to create Hash entries with Symbol keys so the resulting
Hash
would look like:
{ :mykey => "lalala" }