ruby当前目录

作者: lexus
发布时间:2015-07-13 11:31:52

Public Class methods

Changes the current working directory of the process to the given string. When called without an argument, changes the directory to the value of the environment variable HOME, or LOGDIR. SystemCallError (probably Errno::ENOENT) if the target directory does not exist.

If a block is given, it is passed the name of the new current directory, and the block is executed with that as the current directory. The original working directory is restored when the block exits. The return value of chdir is the value of the block. chdir blocks can be nested, but in a multi-threaded program an error will be raised if a thread attempts to open a chdir block while another thread has one open.

   Dir.chdir("/var/spool/mail")    puts Dir.pwd    Dir.chdir("/tmp") do      puts Dir.pwd      Dir.chdir("/usr") do        puts Dir.pwd      end      puts Dir.pwd    end    puts Dir.pwd 

produces:

   /var/spool/mail<br />   /tmp<br />   /usr<br />   /tmp<br />   /var/spool/mail<br />


标签: Ruby
来源:http://www.cnblogs.com/lexus/archive/2011/03/19/1988573.html

推荐: