coding_like_crafting
coding_like_crafting

Reputation: 23

Ruby : How to create an array of integers [0, 10..31]

I need to create an array of integers.

The array contains the number 0, and then number 10 to 31.

I understand that I can type it in, but I really wish there is an eloquent Ruby way to do it.

Upvotes: 2

Views: 328

Answers (2)

Josh
Josh

Reputation: 5721

@xdazz answer is better than this but if you aren't comfortable using the splat operator here is an alternate(less pretty) approach:

[0, (10..31).to_a].flatten

Upvotes: 1

xdazz
xdazz

Reputation: 160843

You could do this:

[0, *10..31]

Upvotes: 10

Related Questions