Skip to content

Conversation

BurdetteLamar
Copy link
Member

No description provided.

@BurdetteLamar BurdetteLamar added the Documentation Improvements to documentation. label Oct 15, 2024
@nobu nobu changed the title [DOC] Tweaks for Array#slice1! [DOC] Tweaks for Array#slice! Oct 16, 2024
@nobu
Copy link
Member

nobu commented Oct 16, 2024

The commit log too.

@BurdetteLamar
Copy link
Member Author

The commit log too.

Thanks, @nobu.

array.c Outdated
Comment on lines 4171 to 4195
* With numeric arguments +start+ and +length+ given,
* removes +length+ elements from +self+ beginning at zero-based offset +start+;
* returns the removed objects in a new array:
*
* a = [:foo, 'bar', 2]
* a.slice!(0, 2) # => [:foo, "bar"]
* a # => [2]
* a = ['a', 'b', 'c', 'd']
* a.slice!(1, 2) # => ["b", "c"]
* a # => ["a", "d"]
* a.slice!(0.1, 1.1) # => ["a"]
* a # => ["d"]
*
* If +start+ is negative, counts backwards from the end of +self+:
*
* a = ['a', 'b', 'c', 'd']
* a.slice!(-2, 1) # => ["c"]
* a # => ["a", "b", "d"]
*
* If <tt>start + length</tt> exceeds the array size,
* removes and returns all elements from offset +start+ to the end:
*
* a = [:foo, 'bar', 2]
* a.slice!(1, 50) # => ["bar", 2]
* a # => [:foo]
* a = ['a', 'b', 'c', 'd']
* a.slice!(2, 50) # => ["c", "d"]
* a # => ["a", "b"]
*
* If <tt>start == a.size</tt> and +length+ is non-negative,
* returns a new empty +Array+.
* returns a new empty array.
Copy link
Member

Choose a reason for hiding this comment

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

I think this is missing the nil return case, where start is out of range.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@peterzhu2118 peterzhu2118 merged commit 4621c9b into ruby:master Oct 16, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements to documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants