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

Corrected Kernel#Array's signature #1433

Conversation

sampersand
Copy link
Contributor

This updates Kernel#Array to the correct signature.

The Array() function works as follows:

  1. If the argument is an array, it's returned immediately
  2. If the argument defines to_ary, then the return value of that is returned
  3. If the argument defines to_a, then the return value of that is returned.
  4. Otherwise, the argument is boxed up in an array and returned.

@sampersand sampersand force-pushed the swesterman/23-08-18/update-Kernel#Array branch from 10d1d91 to dc4c0ea Compare August 18, 2023 21:29
Comment on lines +406 to +408
def self?.Array: (nil) -> [ ]
| [T] (Array[T] x) -> Array[T]
| [T] (_ToAry[T] x) -> Array[T]
Copy link
Contributor

@ParadoxV5 ParadoxV5 Aug 19, 2023

Choose a reason for hiding this comment

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

nil is already a _ToA (a nit, NilClass#to_a RBS also gives [ ] rather than []),
and Array is already a _ToAry and a _ToA

Suggested change
def self?.Array: (nil) -> [ ]
| [T] (Array[T] x) -> Array[T]
| [T] (_ToAry[T] x) -> Array[T]
def self?.Array: [T] (_ToAry[T] x) -> Array[T]

Though we can keep them for readability.

  • Array(an_array)… programmers probably know what they are doïng.
  • Array(nil) … will rubyists think this give [nil] instead?
    • Array(nilable)… I guess this one doesn’t matter that much since there’s Array(array_or_element_or_nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was keeping it for readability. I don't think people will think Array nil #=> [nil] personally

Copy link
Contributor

Choose a reason for hiding this comment

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

If the lack of clarifications does not confuse people then it’s fine to omit them. WDYT, they who merges PRs?

@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