Ruby 2.7 has added
to return the frozen object on which modification was attempted.
It is similar to
NameError#receiver. This can help in pinpointing the frozen object.
In Ruby, we use
freeze on objects,
to make sure objects are not allowed to be mutated by others.
If we try to modify such a frozen object, it will throw a
But with this error, its not easy to simply identify or perform some cleanup operations on the frozen object
We can also manually initialize and throw a
When we try to modify frozen object, it gives
With this error, we can pinpoint the frozen object by calling
While initializing the
FrozenError, we can pass the frozen object as the second argument.
FrozenError#receiver gives us the flexibility
to handle the
specific to receiver,
in a graceful manner.