On Fri, Jan 20, 2012 at 10:05 AM, Eric Christopherson
<echristopherson / gmail.com> wrote:
> On Jan 20, 2012 1:53 AM, "Vikhyat Korrapati" <c / vikhyat.net> wrote:
>>
>> On Friday 20 January 2012 at 1:02 PM, Alex Sweps wrote:
>> > Hello again everyone.
>> > This one should be a quick one for you. I am creating a directory
>> > structure and i want to name some of the folders with a variable but
>> > cannot figure out how. Any help would be great.
>> >
>> > Example: FileUtils.makedirs ('Backup\Test\Test2\@var\@var2@var3')

>> You can interpolate variables into strings using #{}, for example,
>>
>> var1 = 'foo'
>> var2 = 'bar'
>> "Backup\Test\#{var1}\#{var2}" #=> "Backup\Test\foo\bar"
>
> Except that backslashes inside double quotes need to be either doubled, or
> converted into single slashes; e.g.
>
> "Backup\\Test\\#{var1}\\#{var2}"
> "Backup/Test/#{var1}/#{var2}"

To avoid these issues File.join has been invented:

File.join "Backup", "Test", var1, var2
File.join "Backup", "Test", var1, var2 + var3

Assuming var2 and var3 are Strings.  Otherwise

File.join "Backup", "Test", var1, "#{var2}#{var3}"

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/