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

Allow for a custom clone() method #273

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

zeehio
Copy link
Contributor

@zeehio zeehio commented Apr 16, 2023

Hi,

I took the comment from #179 (comment) by @wch and implemented it, adapting contributions from @mb706. I added tests and documentation.

Each commit is self-contained and backwards compatibility should be preserved.

Thanks for your work on R6, it feels easier than RC classes (at least to me!).

- Rename clone() to .clone().
- Create a default clone() that calls .clone()
- Add test for overriding clone()

See
r-lib#179 (comment) for details
If a class defines a post_clone() method, it will automatically be called on the newly created object.

This is convenient because post_clone() allows to modify private fields of the new object at its creation.

See
r-lib#179 (comment)
clone() can now be overridden and it may have additional arguments.

deep_clone() usually calls clone() for some fields, so it makes sense that we pass along additional arguments as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant