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

Updated Kernel conversion methods #1445

Conversation

sampersand
Copy link
Contributor

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 from Numeric | String to just be _ToF, which is what's used `internally.
  • Kernel#Hash: The argument is no longer an Object: Instead, .to_hash is required for its argument, with the special case of nil 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 of Numeric) for the one-argument case
  • Kernel#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 is Numeric, 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 with exception: false (or an unknown boolean value, which may be false), the return type is nil.

Additionally, all the exception: bool variants, when given invalid types but with exception: false, will return nil. That's also been accounted for.

@sampersand sampersand force-pushed the swesterman/23-08-19/update-kernel-conversion-methods branch from ffc5b6e to 5e60ca8 Compare August 21, 2023 19:58
@soutaro soutaro modified the milestones: RBS 3.3, RBS 3.2 Aug 22, 2023
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some newline problems to make the CI pass.

@sampersand sampersand force-pushed the swesterman/23-08-19/update-kernel-conversion-methods branch from 5e60ca8 to 461bf38 Compare August 22, 2023 01:34
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at the CI fails.

@soutaro soutaro enabled auto-merge August 22, 2023 01:51
@soutaro soutaro added this pull request to the merge queue Aug 22, 2023
Merged via the queue into ruby:master with commit 5421329 Aug 22, 2023
22 of 23 checks passed
@soutaro soutaro added the Released PRs already included in the released version label Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

3 participants