lib/ostruct.rb in ostruct-0.5.1 vs lib/ostruct.rb in ostruct-0.5.2

- old
+ new

@@ -105,11 +105,11 @@ # ending with <code>!</code>. # # For all these reasons, consider not using OpenStruct at all. # class OpenStruct - VERSION = "0.5.1" + VERSION = "0.5.2" # # Creates a new OpenStruct object. By default, the resulting OpenStruct # object will have no attributes. # @@ -219,14 +219,17 @@ # OpenStruct. It does this by using the metaprogramming function # define_singleton_method for both the getter method and the setter method. # def new_ostruct_member!(name) # :nodoc: unless @table.key?(name) || is_method_protected!(name) - getter_proc = Proc.new { @table[name] } - setter_proc = Proc.new {|x| @table[name] = x} if defined?(::Ractor) + getter_proc = nil.instance_eval{ Proc.new { @table[name] } } + setter_proc = nil.instance_eval{ Proc.new {|x| @table[name] = x} } ::Ractor.make_shareable(getter_proc) ::Ractor.make_shareable(setter_proc) + else + getter_proc = Proc.new { @table[name] } + setter_proc = Proc.new {|x| @table[name] = x} end define_singleton_method!(name, &getter_proc) define_singleton_method!("#{name}=", &setter_proc) end end