✨ Add Config methods: #to_h
, #update
, and #with
#300
Merged
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.
These methods were originally used to implement
#load_defaults
(to finish #288), and it seems reasonable to add them to the public API.Unlike
SequenceSet
(which I want to have a full API to match Set, Range, and Array), I want to be careful in adding any extra public methods toConfig
. But I think these three are basic enough to be permitted.#to_h
#update
In other words,
#update
does the same thing that#initialize
does with its kwargs.#with
I originally made
#with
create a copy (usingdup
), which meant it was a "sibling" to the receiver, not a child. I did it that way because that's what I wanted for creating the versioned defaults (see #302) and I extracted the method from that code. Also, that's howData#with
works and I had copied some of the rdoc from there.But when I went back to add the tests, it seemed clear to me that the Principle of Least Surprise would expect
#with
to create a child config, inheriting from its creator. I had already created the instance method#new
for that purpose, but#with
is usefully different enough to justify its distinct existence (in my opinion)