Reputation:
I am using the ruby array splat like this:
array = *1,2,3
Output = [1, 2, 3]
count = 10 #Initializing count
Question: I want the array to be continued till the count = 10
when I try this it doesn't work array = *1,..,count
Expected Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Is there any possible way to succeed with this way of approach.
Upvotes: 0
Views: 1079
Reputation: 4798
(1..count)
.to_a, or just (1..count)
if you need Enumerable object but not explicitly Array.
Upvotes: 1
Reputation: 118299
count = 10
count.times.map(&:next)
#=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Upvotes: 0
Reputation: 114248
You can simply use Kernel#Array
:
Array(1..count)
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Upvotes: 2
Reputation: 230531
count = 10
*(1..count) # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Upvotes: 3