From: Curt Sampson Date: 2008-02-09T15:53:47+09:00 Subject: Re: info on block arguments On 2008-02-09 13:22 +0900 (Sat), Russell Me wrote: > 3.times {|x| puts x } > > I see it work, I understand what's going on, but I don't know HOW it's > working. The key point you may be missing is that, unlike blocks in C, a block in ruby is a code definition; it defines a function. This function is an object, like any other, and so you can store it, call it later, etc. So: f = proc { |x| puts(x * 2) } prints nothing but, f now points to an object representing that function. (The "proc" is just an artifact of some inconsistent language design; you don't need it when a function comes before the block definition.) So try calling it: f.call(0) # prints "0" f.call(1) # prints "2" f.call(2) # prints "4" Now, some functions can take a block and call it multiple times.. 3.times(&f) # prints "0", "2", and "4", just as above Next step: get yourself a copy of _The Little Schemer_ and work through it. Then you will achieve much better understanding of many programming languages, including Ruby. cjs -- Curt Sampson +81 90 7737 2974 Mobile sites and software consulting: http://www.starling-software.com