From: Jason Voegele Date: 2001-11-08T00:11:11+09:00 Subject: [ruby-talk:24525] Re: C Extension Help > In message "[ruby-talk:24465] C Extension Help" > on 01/11/07, Jason Voegele writes: > > |I'm trying to write some additional collection classes for Ruby, such > |as Sets, Trees, Bags, Linked Lists, etc. I've got a working Ruby > |version for some of them, but I'm currently attempting to implement a > |Set (backed by a Ruby Hash) as a C extension, but I'm not much of a C > |programmer and I got a run-time error I can't figure out. > > rb_iterate calls block_proc with arguments (element, arg), so that > set_add is called as set_add(element, 0). > > So I modified your source to: [snip source] Thanks, matz, that does seem to work. I've got another question though: how do I create a new instance of Set from C? The docs I've read on this indicate using the Data_Make_Struct (...) or Data_Wrap_Struct(...) functions, but I don't have a struct for my extension. The only instance variable I have in my extension is the Ruby Hash that stores the set elements, and that's set with the rb_iv_set(...) function. Any pointers? Thanks, Jason Voegele