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

Add Array#truncate #10712

Merged

Conversation

HertzDevil
Copy link
Contributor

Closes #10665.

@jkthorne
Copy link
Contributor

jkthorne commented May 14, 2021

I am curious. Why no negative numbers? could negative numbers indicate direction?

example:

array = [1, 2, 3, 4, 5]

array.truncate(array.size - 1, -3) # => [3, 4, 5]

@HertzDevil
Copy link
Contributor Author

That convention has never been adopted by any other methods on Indexable:

array = [1, 2, 3, 4, 5]

array[array.size - 1, -3] # Unhandled exception: Negative count: -3 (ArgumentError)

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

Looks great!

@straight-shoota
Copy link
Member

Thanks @HertzDevil

@HertzDevil HertzDevil deleted the feature/array-truncate branch May 21, 2021 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Array#truncate
4 participants