Updated Kernel conversion methods #1445
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.
This is a merging of the previous individual PRs for conversion methods into one, larger PR. (#1433 , #1434, #1435, #1436, #1437, #1438, #1439). Look at them for a little more in-depth details, adn some discussion topics. Summary of changes is below:
Kernel#Array
: Updated to represent the true definition: Only.to_ary
and.to_a
are used for conversions, and everything else is boxed up in an array.Kernel#Complex
: Added the.to_c
variant.Kernel#Float
: Changed fromNumeric | String
to just be_ToF
, which is what's used `internally.Kernel#Hash
: The argument is no longer anObject
: Instead,.to_hash
is required for its argument, with the special case ofnil
and empty arrays (and only empty arrays) returning empty hashes.Kernel#Integer
: Updated to reflect the ability to pass implicit.to_str
and.to_int
to all variants, and only.to_i
(not being a subclass ofNumeric
) for the one-argument caseKernel#Rational
: Oh boy, this method is a mess. Check out the original issue for more details. tl;dr: If the first argument isn't_ToInt | _ToR
, but isNumeric
, it attempts to do division with it, which allows for returning arbitrary types.Kernel#String
: Simply cleaned up naming; it was semantically correct beforehand.For all conversion methods with an
exception: bool
field, two variants have been added:(..., ?exception: true) -> type
and(..., exception: bool) -> type?
. This reflects the fact that withexception: false
(or an unknown boolean value, which may be false), the return type isnil
.Additionally, all the
exception: bool
variants, when given invalid types but withexception: false
, will returnnil
. That's also been accounted for.