From: "David A. Black" Date: 2008-06-18T15:37:52+09:00 Subject: Re: quick question about how array objects are handled Hi -- On Wed, 18 Jun 2008, ara.t.howard wrote: > > On Jun 17, 2008, at 9:46 PM, Chance Dinkins wrote: > >> Thanks guys, I apperciate it - these.. dynamic methods (is that what >> they are considered?) are a little strange to me. > > they are normal functions but one's which take anonymous functions (blocks) > as arguments. ruby makes this very easy on the eyes, but even C has this > concept: do a 'man qsort' and you'll see > > void > qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, > const void *)); > > note the 'compar' function you can pass in. so, in c, you have to define > that function up front and then pass a pointer to it. in ruby you can do > things like > > compar = lambda{|a,b| a <=> b} > > array.qsort &compar > > or, more compactly > > array.qsort{|a,b| a <=> b} > > of course the method is called 'sort' and not 'qsort', but the principle is > exactly the same. I'd leave room, though, for the fact that in Ruby, you can provide a code block to a method, as part of the syntax of the method call, but you can also send anonymous functions in the argument list. So there's a sense of "The Block", so to speak, separate from any functions you might include as regular arguments. (Yes, I do know about the &block idiom in method signatures :-) David -- Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS June 16-19 Berlin ADVANCING WITH RAILS July 21-24 Edison, NJ See http://www.rubypal.com for details and updates!