On Sun, Dec 30, 2012 at 2:38 AM, Grant Schoep <lists / ruby-forum.com> wrote:
> So, What is the reason for doing Example 1 versus Example 2. The 2nd
> example seems simpler in my book.  My guess is it has something to do
> with how the objects may be used outside the thread?

See 7stud's examples.  It's not about objects but about scope of variables.

Here's another way to demonstrate the effect:

$ ruby -e 'for i in 0..4; Thread.new(i) {|n| sleep 1;p [i,n]} end;sleep 2'
[4, 3]
[4, 4]
[4, 2]
[4, 1]
[4, 0]

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/