Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Collections Ruby Arrays Removing Items From Arrays

Gareth Powell
PLUS
Gareth Powell
Courses Plus Student 7,016 Points

Indexing query

Hi.

To clarify slicing in Ruby, does writing the first number just apply for the index position?

For example, if i wrote '(5, 2)', does this mean to start at position/index 5 and from position 5 onwards, remove 2 items? Further, if one put (8, 1) or (0, 3), it always means start at the position of the first number in the parenthesis?

Thanks,

2 Answers

Owen Tran
Owen Tran
6,822 Points

slice(start, length) will return (not remove) the array at index(start) and for (length) many positions.

slice! will remove them from the array.

see below for a nice explanation: http://ruby-doc.org/core-2.2.2/Array.html#method-i-slice