好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ruby当前目录

ruby当前目录

Public Class methods

Dir[ array ] → array
Dir[ string [, string ...] ] → array

Equivalent to calling Dir.glob ( array, 0) and href="Dir.html#M000629">Dir.glob( ,0) .

Dir.chdir( [ string] ) → 0
Dir.chdir( [ string] ) {| path | block } → anObject

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当前目录的详细内容...

  阅读:36次