Flip the frozen bit on ruby objects, to unfreeze (thaw) them.
Note: You probably don't need to use this gem, you probably want to .dup your objects instead.
The gem supports Ruby 2.7+ with significant safety concerns:
- Native C extension: The only available implementation, extremely dangerous
- Safe fallback: If compilation fails, shows error message and guides users to Object#dup
Strong Recommendation: Use Object#dup instead of trying to unfreeze objects.
The gem uses a native C extension to implement object unfreezing:
gem install thaw- Manipulates Ruby's internal object representation directly
- Will likely cause segmentation faults on modern Ruby versions
- May have platform-specific compilation issues
- Goes against Ruby's fundamental design principles
- Requires a C compiler and Ruby development headers
The dangerous Ruby/Fiddle fallback implementation has been removed for safety. If the native extension isn't available, the gem will show clear error messages and guide users toward Object#dup.
The gem is maintained for:
- Historical compatibility and documentation
- Clear deprecation warnings to guide users toward better alternatives
- Demonstration of the risks involved in low-level object manipulation
The best way to install is with RubyGems:
$ [sudo] gem install thaw
Or better still, just add it to your Gemfile:
gem 'thaw'
string = "hello"
string.frozen?
=> false
string.thawed?
=> true
string.freeze
string.frozen?
=> true
string.thawed?
=> false
string.thaw
string.frozen?
=> false
string.thawed?
=> true
After checking out the repo, run bundle to install dependencies. Then, run bundle exec rspec to run the tests.
Bug reports and pull requests are welcome on GitHub at https://github.com/TwilightCoders/thaw. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Shamelessly ripped from ndnenkov's answer on StackOverflow.
The gem is available as open source under the terms of the MIT License.