From: Phrogz Date: 2009-11-15T13:51:01+09:00 Subject: Re: Array.assoc On Nov 14, 9:48 pm, Phrogz wrote: > On Nov 14, 9:31 pm, Ralph Shnelvar wrote: > > > If I want to find the source to the Class Array ... specifically > > Array.assoc ... where would I look? > > Slim2:~ phrogz$ cd /usr/local/src/ruby-1.9.1-p243/ > Slim2:ruby-1.9.1-p243 phrogz$ grep -E "define_method.+assoc" *.c > array.c:    rb_define_method(rb_cArray, "assoc", rb_ary_assoc, 1); > array.c:    rb_define_method(rb_cArray, "rassoc", rb_ary_rassoc, 1); > hash.c:    rb_define_method(rb_cHash, "assoc", rb_hash_assoc, 1); > hash.c:    rb_define_method(rb_cHash, "rassoc", rb_hash_rassoc, 1); > > So, look for the function named rb_cArray in the array.c file in the > ruby source code. Bah, of course I meant rb_ary_assoc. Looking at your pasted text while typing is bad. :p As penance, here is the source code for that function: VALUE rb_ary_assoc(VALUE ary, VALUE key) { long i; VALUE v; for (i = 0; i < RARRAY_LEN(ary); ++i) { v = rb_check_array_type(RARRAY_PTR(ary)[i]); if (!NIL_P(v) && RARRAY_LEN(v) > 0 && rb_equal(RARRAY_PTR(v)[0], key)) return v; } return Qnil; }