From: Trans Date: 2005-04-13T14:34:35+09:00 Subject: Re: Array#last_index Hi Jabari, > Here's my modification of it to produce Array#last_index. > > static VALUE > rb_ary_last_index(argc, argv, ary) > int argc; > VALUE *argv; > VALUE ary; > { > VALUE nv, result; > long n; > > rb_scan_args(argc, argv, "01", &nv); > n = NUM2LONG(nv); > if (n > RARRAY(ary)->len) n = RARRAY(ary)->len; > return n; > } > > Could someone verify/modify/test this to see if it works. I'm not expert on these matters, to be sure, but if you look at the length method you'll see this: static VALUE rb_ary_length(ary) VALUE ary; { return LONG2NUM(RARRAY(ary)->len); } So a simpler solution for last_index is: static VALUE rb_ary_last_index(ary) VALUE ary; { if (RARRAY(ary)->len == 0) return Qnil; return LONG2NUM(RARRAY(ary)->len-1); } The rb_scan_args isn't needed since this method doesn't take any arguments (let alone any number of them whihc is what that is generally for). Thank you for offering this code, BTW. I've added it to the Suby project. Thanks, T.