Skip to content

Commit 1bfec33

Browse files
coredJoelQ
authored andcommitted
TIL Array#last limit
`Array#last` takes a limit argument. It can return the last `n` elements.
1 parent 55ed615 commit 1bfec33

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ruby/array-last-limit.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Returning a fixed number of items from the tail of a list
2+
3+
[`Array#last`][last docs] takes an argument to limit the number of items to return
4+
from the tail of a list.
5+
6+
```ruby
7+
> [1,2,3,4,5].last(2)
8+
# = > [4, 5]
9+
```
10+
11+
[last docs]: (http://www.ruby-doc.org/core-2.2.0/Array.html#method-i-last)

0 commit comments

Comments
 (0)