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'",
"'09'", "'10'"]

Why is "id" not the array instance. It obviously is an integer.
Otherwise this would have failed with (id +1).

On Feb 25, 2:55 pm, Valery Kvon <[email protected]> wrote:
> 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
> > values. However, what it returns is indeed an array with 500 indexes
> > all with nil values BUT before it returns that array instance, the
> > block appears to execute 500 times passing an actual integer value
> > into the block incrementing by 1 each time. I dont understand why this
> > is happening.
>
> Because 'puts()' always return nil. It just generates STDOUT output.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to