[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Files and variables (noob alert

John Maclean

1/27/2006 9:01:00 PM

Chaps,

Say you've defined a variable:-

a = "l2.txt" # where l2.txt is a file that you know exists
irb(main):009:0> File.exist?("l2.txt")
=> true

#How can I use the variable a within the File.exist(parameter)?
irb(main):012:0> a
=> "l2.xt"

irb(main):013:0> File.exist?(a)
=> false

irb(main):015:0> File.exist?("#@a")
=> false



--
John Maclean
MSc (DIC)
07739 171 531



3 Answers

Wilson Bilkovich

1/27/2006 9:45:00 PM

0

On 1/27/06, John Maclean <info@jayeola.org> wrote:
> Chaps,
>
> Say you've defined a variable:-
>
> a = "l2.txt" # where l2.txt is a file that you know exists
> irb(main):009:0> File.exist?("l2.txt")
> => true
>
> #How can I use the variable a within the File.exist(parameter)?
> irb(main):012:0> a
> => "l2.xt"
>
> irb(main):013:0> File.exist?(a)
> => false
>
> irb(main):015:0> File.exist?("#@a")
> => false
>

That should just work:

irb(main):010:0> File.exist? 'helloworld.rb'
=> true
irb(main):011:0> a = 'helloworld.rb'
=> "helloworld.rb"
irb(main):012:0> File.exist? a
=> true
irb(main):013:0> File.exist? 'nothere'
=> false


John Maclean

1/27/2006 9:57:00 PM

0

Thanks!
On Sat, 28 Jan 2006 06:44:42 +0900
Wilson Bilkovich <wilsonb@gmail.com> wrote:

> On 1/27/06, John Maclean <info@jayeola.org> wrote:
> > Chaps,
> >
> > Say you've defined a variable:-
> >
> > a = "l2.txt" # where l2.txt is a file that you know exists
> > irb(main):009:0> File.exist?("l2.txt")
> > => true
> >
> > #How can I use the variable a within the File.exist(parameter)?
> > irb(main):012:0> a
> > => "l2.xt"
> >
> > irb(main):013:0> File.exist?(a)
> > => false
> >
> > irb(main):015:0> File.exist?("#@a")
> > => false
> >
>
> That should just work:
>
> irb(main):010:0> File.exist? 'helloworld.rb'
> => true
> irb(main):011:0> a = 'helloworld.rb'
> => "helloworld.rb"
> irb(main):012:0> File.exist? a
> => true
> irb(main):013:0> File.exist? 'nothere'
> => false
>
>
>


--
John Maclean
MSc (DIC)
07739 171 531



John Maclean

1/27/2006 10:19:00 PM

0

irb(main):006:0> x = 'l2.txt' if File.exist? 'l2.txt'
=> "l2.txt"
irb(main):007:0> x
=> "l2.txt"

Thanks ever so much for your speedy reply. Now I'm starting to get
somewhere!


On Sat, 28 Jan 2006 06:44:42 +0900
Wilson Bilkovich <wilsonb@gmail.com> wrote:

> On 1/27/06, John Maclean <info@jayeola.org> wrote:
> > Chaps,
> >
> > Say you've defined a variable:-
> >
> > a = "l2.txt" # where l2.txt is a file that you know exists
> > irb(main):009:0> File.exist?("l2.txt")
> > => true
> >
> > #How can I use the variable a within the File.exist(parameter)?
> > irb(main):012:0> a
> > => "l2.xt"
> >
> > irb(main):013:0> File.exist?(a)
> > => false
> >
> > irb(main):015:0> File.exist?("#@a")
> > => false
> >
>
> That should just work:
>
> irb(main):010:0> File.exist? 'helloworld.rb'
> => true
> irb(main):011:0> a = 'helloworld.rb'
> => "helloworld.rb"
> irb(main):012:0> File.exist? a
> => true
> irb(main):013:0> File.exist? 'nothere'
> => false
>
>
>


--
John Maclean
MSc (DIC)
07739 171 531