different results with File.exists?

  • Thread starter Mehdi Karamnejad
  • Start date
M

Mehdi Karamnejad

when I use a string constant with File.exists? like the following ,it
works fine:
File.exists?("/home/sepehr")
but when I get the string from user:
path=gets
if File.exists?(path) then
 
R

Robert Klemme

2009/9/8 Mehdi Karamnejad said:
yeah,that was it! thanks ;)

Additional hint: use p to debug output what you have. e.g.

path=gets
p path
if File.exists?(path) then

Cheers

robert
 
M

Marc Heiler

Additional hint: use p to debug output

Or use pp!

With arrays and hashes pp beats p easily! :>
 
D

David A. Black

Hi --

Additional hint: use p to debug output what you have. e.g.

path=gets
p path
if File.exists?(path) then

Meta-additional hint: in 1.9, p returns its argument(s), so if you
have:

path = gets

you can just change it to:

p path = gets

which makes for slightly easier back-and-forth between the p version
and the non-p version.


David

--
David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com
Ruby/Rails training, mentoring, consulting, code-review
Latest book: The Well-Grounded Rubyist (http://www.manning.com/black2)

September Ruby training in NJ has been POSTPONED. Details to follow.
 
R

Robert Klemme

2009/9/9 David A. Black said:
Hi --



Meta-additional hint: in 1.9, p returns its argument(s), so if you
have:

=A0path =3D gets

you can just change it to:

=A0p path =3D gets

which makes for slightly easier back-and-forth between the p version
and the non-p version.

David, did you rather mean "path =3D p gets"? Because "p path =3D gets"
does work in pre 1.9 already. :)

Kind regards

robert


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,264
Latest member
FletcherDa

Latest Threads

Top