From: sto.mar@... Date: 2012-08-19T16:56:18+09:00 Subject: Re: Access returned value in a string? Am 19.08.2012 02:17, schrieb Dave Castellano: > Tried that... > I have the following... > questions = [ > "A slide is placed #{u = rand(3..15)} cm to the left of a lens. The > image is in perfect focus on the screen #{v = rand(1..4)} m to the right > of the lens. What is the power of the lens?", > "A slide is placed #{u = rand(3..15)} cm to the left of a +#{p = > rand(3..15)} D lens. At what distance will the screen need to be placed > to the right of the lens to have the image be in focus?", > "An image is in focus #{v = rand(3..15)} m to the right of a +#{p = > rand(3..15)} D lens. At what distance (in cm) to the left of the lens > is the slide placed?" > > puts questions[0] > puts u > puts v > I can't figure out why but the values of u and v returned are always the > values of the first instance of #{} in the second and third question. They are the values of the last assignment to u and v. All the assignments are done when the questions array is defined, so u and v are reassigned by the second and third question. --