Ruby on Rails
PhpArray_fill

Ruby



array = []

array << "value1","value2","value3" 



array = ["value1","value2","value3"]

To emulate the repetition of the array_fill function, you can do something like the following, which will initialize and then fill an array.


a = []
8.times { a << "value" }

A much more concise way of doing the same thing:


Array.new(8, 'value')

Arrays in PHP are a hybrid of hash and array. Ruby will fill in the preceding indexes with nil, unless you start from zero. If you need to start from another index, you can use the looping syntax below


a = []
(2..3).each { |i| a[i] = 'value' }

With Ruby, there are many ways to do the same thing. Experiment and find what works best for you.