From: Robert Warning Date: 2002-08-16T13:52:57+09:00 Subject: Re: Hello everyone! Patrick Bennett wrote: > procs can be used as standalone 'closures' and passed around/called as > callable functions (via the returned proc object). > ie: > > def testFunc( obj ) > obj.call > end > > bleah = proc { puts "something" } > testFunc( bleah) > ---- > something > > They can substitute as blocks by passing the proc (with a preceeding > &) as a method parameter to something expecting a block. This turns > the proc into a block for that method. > ie: > foo = proc { |val| puts val } > a = [1,2,3] > a.each( &foo ) > ----- > 1 > 2 > 3 > > I'm missing a couple other variations, but you should get the idea. > You might want to dig into the Thomas/Hunt book a bit more. > > > Robert Warning wrote: > >> I'm just learning ruby and so far everything has been great (using >> the Thomas and Hunt book), but I don't quite understand how proc >> objects (and its call method) relate to code blocks. If anyone could >> explain I would greatly appriciate it. >> > > > Thanks, blocks in the sence that Ruby uses them is still kinda wierd to me even after going over it a few times. I guess I'm too acustmed to C style blocks. The closest thing ruby has to C style blocks is the ALGOL style END blocks. Don't take that as a fact that I know alot about programing languages :P its just one of those quirky things I know from looking at some ALGOL (yes that 1960's thingamajiger) source code once. My only real experiance with programming is with BASIC php and very little perl. When I was 11 I attempted C after BASIC and had a brain overload. Havn't touched C since then :).