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

Array way #572

Closed
WaKeMaTTa opened this issue May 25, 2016 · 2 comments
Closed

Array way #572

WaKeMaTTa opened this issue May 25, 2016 · 2 comments

Comments

@WaKeMaTTa
Copy link

Hello,

which is the difference between:

a = *(1..3)
# => [1, 2, 3]

and this:

a = (1..3).to_a
# => [1, 2, 3]

And which is accepted? And there is another way more readable?

@kevinfalting
Copy link

This is a good question and one that I've wondered about myself. I asked some of the rubyists I know and they opted for:

a = (1..3).to_a

for readability reasons.

Also .to_a is a faster operation.

So, .to_a is faster and more explicit.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 12, 2016

Indeed. I'd definitely go for .to_a over using the splat operator in this situation. Always optimize for readability!

@bbatsov bbatsov closed this as completed Dec 12, 2016
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

No branches or pull requests

3 participants