On Sun, Dec 30, 2012 at 2:38 AM, Grant Schoep <[email protected]> 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/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google 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 https://groups.google.com/d/forum/ruby-talk-google?hl=en