score:2

Accepted answer

In ruby you can save different type of the element in the single array like following

arr = [1, 1.0, "This is a String", {abc: pqr}, [6]]
#arr[0].class = Fixnum
#arr[1].class = Float
#arr[2].class = String
#arr[3].class = Hash
#arr[4].class = Array

So if you want to save array of array like following

[["value1", 1.0], ["value2", 2.0]]

Use following

array = []
@products.each do |p|
  array << [p.title, p.price]
end

OR just

array =  @products.collect{|p|  [p.title, p.price]}

Edited to show the access the 2D Array

arr = [["value1", 1.0], ["value2", 2.0]]
#arr[0] = ["value1", 1.0] 
#arr[0][0] = "value1" 
#arr[0][1] = 1.0
#arr[1] = ["value2", 2.0]
#arr[1][0] = "value2" 
#arr[1][1] = 2.0

Related Query

More Query from same tag