“The instance_variable_set method is the bane of anyone who wants to truly protect their object’s state. Because of it’s existence, it is basically impossible to truly hide your objects’ internal state in Ruby.”
Why not override that method if you don’t like how it behaves?
Even if you override that method, someone trying to break into your object can still grab it from elsewhere using the “method” method, and then reattach it to the object. But regardless of instance_variable_set, you can always reopen the class and add a method that accesses the instance variable. E.g.
Basically, if you use a variable with the @ symbol, it’s just about impossible to hide.
It’s not “instance_variable_set” that’s the problem, it’s just the nature of dynamic languages and reasonable expectations.