Forum: Ruby want to create a file with variable name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
44d59c6c5a7e3435409ebe94c9aa9db5?d=identicon&s=25 Srikanth Jeeva (srikanth_j)
on 2008-12-12 14:13
hi i want to create a file name, with that variable name..

for example..

a=10

f=File.open('a.txt','a')
created file name is a.txt
but
i want the file as 10.txt

can any one help??
C03a16deabdeda0e3bda6dc2dcea5426?d=identicon&s=25 John Slobbe (johnslobbe)
on 2008-12-12 14:27
(Received via mailing list)
Try:

f = File.open("#{a}.txt",'a')

Regards, John.
44d59c6c5a7e3435409ebe94c9aa9db5?d=identicon&s=25 Srikanth Jeeva (srikanth_j)
on 2008-12-12 14:29
John Slobbe wrote:
> Try:
>
> f = File.open("#{a}.txt",'a')
>
> Regards, John.

Thank You so much john..
its working.
This topic is locked and can not be replied to.