diff options
author | rm155 <[email protected]> | 2021-08-20 08:12:28 -0400 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-09-28 17:30:06 +0900 |
commit | cefa02957312620187cfd81219650304032ae787 (patch) | |
tree | e1dfdb34a3dbc9e59de32b2a3a8a7500c1d726e0 /lib/ostruct.rb | |
parent | 83662f1d9968204a43adf4a94d6872967b65f712 (diff) |
[ruby/ostruct] Allow properties to be accessed even when the object is moved to another Ractor (https://github.com/ruby/ostruct/pull/29)
https://github.com/ruby/ostruct/commit/d85639f2f5
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r-- | lib/ostruct.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index c03d912d6f..8680374499 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -221,8 +221,14 @@ class OpenStruct # def new_ostruct_member!(name) # :nodoc: unless @table.key?(name) || is_method_protected!(name) - define_singleton_method!(name) { @table[name] } - define_singleton_method!("#{name}=") {|x| @table[name] = x} + getter_proc = Proc.new { @table[name] } + setter_proc = Proc.new {|x| @table[name] = x} + if defined?(::Ractor) + ::Ractor.make_shareable(getter_proc) + ::Ractor.make_shareable(setter_proc) + end + define_singleton_method!(name, &getter_proc) + define_singleton_method!("#{name}=", &setter_proc) end end private :new_ostruct_member! |