From: Jari Williamsson Date: 2008-02-08T18:45:29+09:00 Subject: Re: info on block arguments Russell Me wrote: > 3.times {|x| puts x } > > the output is 0,1,2 because... x is initially nil and a value of 1 is > returned (by... what?) to .times? is that right? Perhaps the easiest way is to explain with a method that basically does the same thing as times: --- class Fixnum def my_times return if !block_given? i = 0 while (i < self) yield(i) i += 1 end end end 3.my_times {|x| puts x } --- * The line "return if !block_given?" is used to prevent crash if the method is called without code block. * In the case of Fixnum above, "self" is the same as the digit * The code block is called by "yield(i)", but the value of i will be named x in your code block. Best regards, Jari Williamsson