Add forward_missing_to @object to Colorize #13005
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working with code in a few other areas, including Benchmark::IPS, I tripped a little over the fact that a colorized String (or any other object) becomes an instance of
Colorize::Object(T)
, and can no longer be used as it's original object type.There are many times where one may want to inject some color or mode changes into a String and still transparently use the resulting object as if it were a String.
This patch adds a
forward_missing_to @object
, which in most cases where the type signature allows it, lets a colorized object like a colorized String duck type its way through life as if it were still a String, which simplifies many things.The patch also adds a
mode
method like thefore
andback
methods, because without it,forward_missing_to
caused spec failures. I also added a basic spec to exercise the method forwarding as part of this change.