From: merch-redmine@... Date: 2020-05-26T02:34:21+00:00 Subject: [ruby-core:98516] [Ruby master Bug#16906] Calling Thread#thread_variable? in IRB sometimes produce wrong result Issue #16906 has been updated by jeremyevans0 (Jeremy Evans). I can confirm this bug. It's because `thread_variable?` uses different code than `thread_variable_get` and `thread_variable_set`. Removing the `rb_check_id` and switching `ID2SYM` to `rb_to_symbol` fixes it. I've added a pull request for this, and will merge if it passes CI: https://github.com/ruby/ruby/pull/3145 ---------------------------------------- Bug #16906: Calling Thread#thread_variable? in IRB sometimes produce wrong result https://bugs.ruby-lang.org/issues/16906#change-85791 * Author: tyok (Mohammad Satrio) * Status: Open * Priority: Normal * ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- Consider this script: ``` ruby Thread.current.thread_variable_set("ab", 12) puts Thread.current.thread_variable?("ab") puts Thread.current.thread_variable?(:ab) puts Thread.current.thread_variable?("ab") ``` When I put the script above in a file and run it, I got three `true` as expected: ``` bash-3.2$ ruby test.rb true true true ``` But when I copy each line to IRB, I got false on the first check: ``` shell bash-3.2$ irb irb(main):001:0> Thread.current.thread_variable_set("ab", 12) => 12 irb(main):002:0> puts Thread.current.thread_variable?("ab") false => nil irb(main):003:0> puts Thread.current.thread_variable?(:ab) true => nil irb(main):004:0> puts Thread.current.thread_variable?("ab") true => nil ``` I expect it to print three `true` in IRB, just like when I run the script via file. ---Files-------------------------------- test.rb (173 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: