From: Wybo Dekker Date: 2012-08-19T14:34:39+09:00 Subject: Re: Access returned value in a string? Start by doing: u,v,p=nil -- Wybo On 19 aug. 2012, at 02:17, Dave Castellano wrote: > Stefan Codrescu wrote in post #1072788: >> Additionally you could do something like >> questions = [ "a slide is placed #{a=rand(3..15), a} cm to the left of a >> lens." >> a could then be passed to some function. >> >>> questions = >>> "A slide is placed #{rand(3..15)} cm to the left of a lens." >> >> StefaN > > 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. > > -- > Posted via http://www.ruby-forum.com/. >