From: sto.mar@... Date: 2012-08-17T17:05:41+09:00 Subject: Re: variable from array to function to array Am 17.08.2012 02:39, schrieb Dave Castellano: > anyone know if it is possible to pass elements from an array (eg 20,50 ) > to the function > number_range(min,max) and have the returned value used in the variable > |age| below... > > > def number_range(min,max) # Chooses a random number within > specified range. > num = min + rand(max - min) > end This will never return max! Use min + rand(max - min + 1) or simply rand(min..max) > array = [ lambda { |age| "An #{age} year old..."}, 20, 50 ] > > puts array[0][age returned from number_range method] This would work: array = [lambda { |age| "An #{age} year old..."}, 20, 50] puts array[0][rand(array[1]..array[2])] But this approach seems very odd to me. What are you trying to do? Why not do it like this: def random_age_string(range) "A #{rand(range)} year old" end puts random_age_string(20..40) But it is rather impossible to provide useful help unless you give us the bigger picture. --