3

Dir.chdir can change to an absolute path:

Dir.chdir("/var/spool/mail")

Can it change to a relative path such as:

Dir.chdir("log/spool/mail")
sawa
  • 165,429
  • 45
  • 277
  • 381
s-cho-m
  • 967
  • 2
  • 13
  • 28
  • possible duplicate of [Can chdir() accept relative paths?](http://stackoverflow.com/questions/4998530/can-chdir-accept-relative-paths) – Alfabravo Sep 01 '15 at 04:05
  • @Alfabravo, not sure I'd consider that a dupe since it has nothing to do with Ruby per se. Ruby (and any other language) is free to expand (or contract) the functionality of any system calls as it sees fit. For example, `bash` provides `~` as an extension even though `chdir()` knows nothing of it. – paxdiablo Sep 01 '15 at 04:19
  • 1
    @paxdiablo looks like a wrong call, indeed. Didn't see that one tag and reminded of the other question. Thanks for the feedback. – Alfabravo Sep 01 '15 at 04:21

2 Answers2

3

Yes. It will accept relative paths.

Dir.chdir("log/spool/mail")
sawa
  • 165,429
  • 45
  • 277
  • 381
0

Yes, although the docs don't make it very clear, it can certainly do so.

See the following transcript, which first goes to the root directory then uses relative movement to get to /tmp:

pax$ ruby <<EOF
...>    puts ""
...>    Dir.chdir("/")
...>    puts Dir.pwd
...>    Dir.chdir("tmp")
...>    puts Dir.pwd
...> EOF

/
/tmp
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953