Skip to content

TIL Ruby: One liner To Get First and Last Elements In An Array #15

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

Merged
merged 1 commit into from
Dec 3, 2015

Conversation

stevenyap
Copy link
Contributor

Here's cool way to get the first and last elements of an array in one
liner
using splat:

first, *, last =  [1, 2, 3, 4, 5]
first # => 1
last # => 5

Here's cool way to get the first and last elements of an array _in one
liner_ using splat:

```ruby
first, *, last =  [1, 2, 3, 4, 5]
first # => 1
last # => 5
```
WayneTng added a commit that referenced this pull request Dec 3, 2015
TIL Ruby: One liner To Get First and Last Elements In An Array
@WayneTng WayneTng merged commit 401fd66 into master Dec 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants