From: "ko1 (Koichi Sasada)" Date: 2012-10-30T09:17:10+09:00 Subject: [ruby-core:48577] [ruby-trunk - Bug #7097][Closed] Thread locals don't work inside Enumerator Issue #7097 has been updated by ko1 (Koichi Sasada). Status changed from Assigned to Closed Target version set to 2.0.0 This "feature" was introduced. ---------------------------------------- Bug #7097: Thread locals don't work inside Enumerator https://bugs.ruby-lang.org/issues/7097#change-31962 Author: tenderlovemaking (Aaron Patterson) Status: Closed Priority: Normal Assignee: ko1 (Koichi Sasada) Category: Target version: 2.0.0 ruby -v: ruby 2.0.0dev (2012-09-25 trunk 37032) [x86_64-darwin12.2.0] I set a thread local outside an Enumerator. The Enumerator runs inside the same thread where I set the local. I would expect the thread local to be available since I am in the same thread, but it is not. Here is a test that shows the problem: require 'minitest/autorun' class ThreadLocalBreaks < MiniTest::Unit::TestCase def test_thread_local_in_enumerator Thread.current[:foo] = "bar" thread, value = Enumerator.new { |y| y << [Thread.current, Thread.current[:foo]] }.next assert_equal Thread.current, thread # passes assert_equal Thread.current[:foo], value # fails end end -- http://bugs.ruby-lang.org/