Project

General

Profile

Actions

Bug #16906

closed

Calling Thread#thread_variable? in IRB sometimes produce wrong result

Added by tyok (Mohammad Satrio) over 4 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]
[ruby-core:98480]

Description

Consider this script:

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:

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) test.rb Sample test file tyok (Mohammad Satrio), 05/22/2020 02:30 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0