diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-12-22 17:07:23 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-12-22 23:32:18 +0900 |
commit | cae8bbfe6271a15cf212a83a9c3ac3fedcdc7718 (patch) | |
tree | 6369150fe7f5ac02855a49e801dc46cc97a1ad6f /lib | |
parent | 034c19ce288b951cfaf3bbd996ce19e14fdeb502 (diff) |
pp is ractor-ready.
`@sharing_detection` is only one obstruction to support pp on
non-main ractors, so make it ractor-local.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3973
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pp.rb | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -93,11 +93,24 @@ class PP < PrettyPrint end # :startdoc: - @sharing_detection = false - class << self - # Returns the sharing detection flag as a boolean value. - # It is false by default. - attr_accessor :sharing_detection + if defined? ::Ractor + class << self + # Returns the sharing detection flag as a boolean value. + # It is false (nil) by default. + def sharing_detection + Ractor.current[:pp_sharing_detection] + end + def sharing_detection=(b) + Ractor.current[:pp_sharing_detection] = b + end + end + else + @sharing_detection = false + class << self + # Returns the sharing detection flag as a boolean value. + # It is false by default. + attr_accessor :sharing_detection + end end module PPMethods |