The original code looks like this:
module Acme
class Address
STREET_NAME = "123 acme inc drive".freeze
..
..
end
end
This is a 3rd party gem, I was hoping I could modify the STREET_NAME variable in a initializer somehow, without having to edit the source code. Is this possible?
Just reassign it:
Freezing an object freezes just that: the object, not the variable (reference) itself. Reassigning a constant will give you a warning though:
since it’s generally not a good idea to reassign a constant—but this is Ruby, and since everything is dynamic, constants aren’t really constant. Doing this in an initializer should work just fine.