Actions
Feature #17401
closedThe class `Ractor::MovedObject` should not be frozen
Description
If Ractor::MovedObject
can be not frozen that would be more helpful than currently. For example, to implement a helpful inspect
in pure Ruby 3.0 like in #17393
It is currently possible to go around the fact that it is frozen with refinements:
using Module.new {
refine Ractor::MovedObject do
def inspect
"I was moved! Don't use me!"
end
end
}
o = Object.new
Ractor.new{ receive }.send(o, move:true)
puts o.inspect # => "I was moved! Don't use me!"
Another (ugly) way to bypass the fact that it is frozen without refinements is to modify its ancestor:
module Ext
def inspect
return super unless Ractor::MovedObject === self
"I was moved! Don't use me!"
end
end
BasicObject.prepend Ext
o = Object.new
Ractor.new{ receive }.send(o, move:true)
p o # => "I was moved! Don't use me!"
My point remain that this "security" can be bypassed unless it is stricly necessary it, it would be nice to unfreeze the class. It could be documented that this is experimental / not recommended to modify the class in production, for example.
Actions
Like0
Like0Like0