Re: [Rails] question about passing an array iterator instance to a block

2012-02-28 Thread Dave Aronson
On Sat, Feb 25, 2012 at 15:15, Valery Kvon adda...@gmail.com wrote: There must be code inside like that: if block_given?   yield index end That wouldn't do the setting of the values in the array. Maybe: if block_given? size.times { |index| self yield index } end or, if it already

[Rails] question about passing an array iterator instance to a block

2012-02-25 Thread John Merlino
I was always under assumption that the block accepts the return value of the iterator as the argument to the block, but look at this: Array.new(500) do | i | puts i end I expect i to be an array instance with 500 indexes all will nil values. However, what it returns is indeed an array

Re: [Rails] question about passing an array iterator instance to a block

2012-02-25 Thread Valery Kvon
On 25.02.2012, at 23:41, John Merlino wrote: I was always under assumption that the block accepts the return value of the iterator as the argument to the block, but look at this: Array.new(500) do | i | puts i end I expect i to be an array instance with 500 indexes all will nil

Re: [Rails] question about passing an array iterator instance to a block

2012-02-25 Thread Valery Kvon
On 26.02.2012, at 0:07, John Merlino wrote: thanks for response but that was just an example and not really what my question was about. Perhaps this is a better example: Array.new(10) do |id| ? '#{(id + 1).to_s.rjust(2,0)}' end = ['01', '02', '03', '04', '05', '06', '07', '08',