From: Sean O'Halpin Date: 2012-08-18T08:15:04+09:00 Subject: Re: variable from array to function to array On Fri, Aug 17, 2012 at 1:15 PM, Dave Castellano wrote: > The bigger picture... I am saving multiple question templates in a > array and need to store all the info (the question, the min and max > ranges, the units of measure etc assoc with each question. The > associated info is used to build the question ... eg in question one, > need to pass 20,40 to number_range(min,max) and use the returned value > as u. If you're using ruby 1.9, you can use the new hash interpolation syntax: puts "Hello %{who}" % { :who => "world" } outputs Hello world For example: def number_range(min,max) min + rand(max - min + 1) end array =[ [ "A slide is placed %{value} %{unit} to the left of a lens...", 20, 40, "cm"], [ "An image is in focus %{value} %{unit} to the right of a...", 10, 25, "mm" ], ] array.each do |item| text, min, max, unit = item puts text % { :value => number_range(min, max), :unit => unit } end puts "Hello %{who}" % { :who => "world" } Regards, Sean