Is it possible to mark an instance variable such as @var as unassingnable, such that the following test would pass? The aim is simulate a readonly variable:
class Test
def initialize(var)
@var = var
@var.freeze
make_unassignable(:@var)
end
def set_var(new_var)
@var = new_var
end
def make_unassignable(symbol)
#insert algorithm here
end
end
test = Test.new('some var')
expect { test.set_var = 'some other var' }.to raise_error
expect { test.instance_variable_set(:@var, 'some other var') }.to raise_error
$<), but Ruby doesn't expose this feature through its API.