From: Robert Klemme Date: 2008-02-08T17:59:50+09:00 Subject: Re: info on block arguments 2008/2/7, Day : > I think it's kind of funny no one's pointed this out yet. The anatomy > of a block: > { |argument, list| code.to(execute) } > > A block is built a little like a method, though it has no name and > only exists while it is executing (as others has said). I disagree with the "it exists only while it is executing" bit. A block is an anonymous function and lives as long as regular methods do. I.e. you declare them, the code is parsed and compiled into an internal representation and can be invoked any number of times (even concurrently). The code lives all the time but there is any number (including 0) of active invocations on them at any given point in time of program execution. > It's almost like... passing a little method to > another method as an argument, knowing that the method you're calling > will execute that code in a certain way (just like you know it'll do > other stuff to normal arguments you pass in) and give you back > something helpful. Exactly. A block can be seen as an anonymous callback function. > I hope that's clear. Sometimes I get rambly and don't actually explain anything. I think that was pretty clear. Kind regards robert -- use.inject do |as, often| as.you_can - without end