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#Integer #1437

Conversation

sampersand
Copy link
Contributor

This updates Kernel#Integer to be more correct.

Notably, in the one-argument form, the first argument needs to either define to_int, to_i, or to_str to be convertible. Additionally, int he two-argument form, the first argument just needs to define to_str, and the second to_int.

Like the other conversion fuctions, if exception: false is explicitly given, the return value is an Integer?. Additionally, (untyped, ?untyped, exception: false) -> nil was added, as any types are accepted when exception: false is supplied.

One thing to note, however, is that this definition isn't technically complete: The one-argument form can technically take a second argument. However, this argument needs to either:

  1. Define to_int, which when called returns 0, or
  2. Not define to_int!

(For example, Integer 123, :a is valid.) Neither of these things is really possible to do in RBS, and attempting to force it in wouldn't work well, so I've leftit out.

@ParadoxV5
Copy link
Contributor

One thing to note, however, is that this definition isn't technically complete: The one-argument form can technically take a second argument. However, this argument needs to either:

  1. Define to_int, which when called returns 0, or
  2. Not define to_int!

(For example, Integer 123, :a is valid.) Neither of these things is really possible to do in RBS, and attempting to force it in wouldn't work well, so I've leftit out.

Zero based is documented but no example given. This is doable through an interface. The fact that such case accepts non-String arg1, howëver, is more like an oddity rather than a worthwhile feature. Same goes for the acceptance of a non-_ToInt arg2, which cannot be documented in RBS (and might not even be Ruby-like) because it’s the opposite of duck-types.

@sampersand
Copy link
Contributor Author

Consolidated in #1445

@sampersand sampersand closed this Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants