From: Dave Castellano Date: 2012-08-16T01:07:51+09:00 Subject: Re: Variable in string in array Robert Klemme wrote in post #1072441: > On Wed, Aug 15, 2012 at 2:46 PM, Dave Castellano > wrote: >> Anybody know how to embed a #{} in a string and then place the string in >> an array? >> >> eg. >> >> array =["An #{age} year old..."] >> >> returns >> > /Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/catch_exception.rb:15 > > If the error originated in that line it can only be caused by invoking > method "age". Do you have a stack trace? > >> I tried adding single quotes >> array =[' "An #{age} year old..." '] and this accepted the string but >> the variable was also converted to a string, so lost as a variable. > > Do you want the #{...} to be literally present in the String or do you > want to evaluate it when placing the String in the Array? > > Kind regards > > robert I want to place it in the array as a string, evaluate it later... eg: age = "11" puts array[0] > An 11 year old... -- Posted via http://www.ruby-forum.com/.