From: Neil Conway Date: 2001-09-09T05:13:34+09:00 Subject: [ruby-talk:21013] length of Ruby array from C? Hi all, I've been experimenting with writing some Ruby extensions in C. In order to find the length of a Ruby array, I needed to do this: /* -------- */ VALUE ary; int ary_length; /* ... assign a Ruby array to "ary" ... */ ary_length = RARRAY(ary)->len; /* -------- */ There are 2 problems with this, IMHO: 1) undocumented: I had to look through the source to find this 2) clumsy: if this is the only way to get the length, could we perhaps have some syntactic sugar? For instance, a function (or macro) rb_ary_length(VALUE), which returns the length of the specified array as a C integer. Since this is a relatively common operation, I think it would be worthwhile to make it a bit easier for extension writers. Otherwise, I've found Ruby's C API very pleasant. Cheers, Neil