[ruby-core:104958] [Ruby master Bug#16906] Calling Thread#thread_variable? in IRB sometimes produce wrong result
From:
"greneholt (Connor McKay)" <noreply@...>
Date:
2021-08-17 22:55:40 UTC
List:
ruby-core #104958
Issue #16906 has been updated by greneholt (Connor McKay).
This needs to be backported to 2.7.x. It wasn't fixed in 2.7.4.
----------------------------------------
Bug #16906: Calling Thread#thread_variable? in IRB sometimes produce wrong result
https://bugs.ruby-lang.org/issues/16906#change-93320
* Author: tyok (Mohammad Satrio)
* Status: Closed
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>