On 3 Sep 2007, at 16:21, 7stud -- wrote: > Alex Gutteridge wrote: >> So short answer: Hash#[] calls Hash#default which in the case of Hash >> objects with an associated Proc calls the Proc. >> > > Thanks for the explanation. So, is correct to assume that in the > source > code for Hash#default there is a line somewhere that says something > like: > > yield hash, key Well proc.call(hash,key) really, which is almost (sort of) the same thing! Here is the source code from hash.c with my comments: static VALUE rb_hash_default(argc, argv, hash){ VALUE key; rb_scan_args(argc, argv, "01", &key); if (FL_TEST(hash, HASH_PROC_DEFAULT)) { //Test if default Proc is present if (argc == 0) return Qnil; return rb_funcall(RHASH(hash)->ifnone, id_call, 2, hash, key); //If so call the procs 'call' method } //with 'hash' and 'key' as args return RHASH(hash)->ifnone; } Alex Gutteridge Bioinformatics Center Kyoto University