Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forward_missing_to @object to Colorize #13005

Closed

Conversation

wyhaines
Copy link
Contributor

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 the fore and back 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.

@straight-shoota
Copy link
Member

This doesn't click with me right away. Could you detail a bit about your use cases? Ideally, please create an issue for this so we can separate general discussion about this feature from the concrete implementation in this PR.

@asterite
Copy link
Member

and still transparently use the resulting object as if it were a String

In my mind colorize is the last thing you call before moving that object into the output. If you need to do some things with the original string, I would preserve that as a separate variable.

I think adding forward_missing_to would make things a bit harder to understand.

@wyhaines
Copy link
Contributor Author

As requested, to short circuit a lot of discussion on the PR, I have created an issue:

#13007

@wyhaines
Copy link
Contributor Author

I am closing this PR, having been convinced that the use case isn't generally worth the potential downsides.

@wyhaines wyhaines closed this Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants