org.jruby
Class RubyDir

java.lang.Object
  extended byorg.jruby.RubyObject
      extended byorg.jruby.RubyDir
All Implemented Interfaces:
java.lang.Cloneable, IRubyObject

public class RubyDir
extends RubyObject

.The Ruby built-in class Dir.

Author:
jvoegele

Nested Class Summary
 
Nested classes inherited from class org.jruby.RubyObject
RubyObject.Finalizer
 
Field Summary
protected  JRubyFile dir
           
 
Fields inherited from class org.jruby.RubyObject
instanceVariables, isTrue, metaClass, NEVER, OBJECT_ALLOCATOR
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyDir(Ruby runtime, RubyClass type)
           
 
Method Summary
static IRubyObject chdir(IRubyObject recv, IRubyObject[] args, Block block)
          Changes the current directory to path
static IRubyObject chroot(IRubyObject recv, IRubyObject path)
          Changes the root directory (only allowed by super user).
 IRubyObject close()
          Closes the directory stream.
static RubyClass createDirClass(Ruby runtime)
           
 IRubyObject each(Block block)
          Executes the block once for each entry in the directory.
 RubyArray entries()
           
static RubyArray entries(IRubyObject recv, IRubyObject path)
          Returns an array containing all of the filenames in the given directory.
static IRubyObject foreach(IRubyObject recv, IRubyObject _path, Block block)
          Executes the block once for each file in the directory specified by path.
protected static java.util.List getContents(java.io.File directory)
          Returns the contents of the specified directory as an ArrayList containing the names of the files as Java Strings.
protected static java.util.List getContents(java.io.File directory, Ruby runtime)
          Returns the contents of the specified directory as an ArrayList containing the names of the files as Ruby Strings.
protected static JRubyFile getDir(Ruby runtime, java.lang.String path, boolean mustExist)
          Returns a Java File object for the specified path.
static RubyString getHomeDirectoryPath(IRubyObject recv)
           
static IRubyObject getHomeDirectoryPath(IRubyObject recv, java.lang.String user)
          Returns the home directory of the specified user on the system.
static RubyString getwd(IRubyObject recv)
          Returns the current directory.
static IRubyObject glob(IRubyObject recv, IRubyObject[] args, Block block)
          Returns an array of filenames matching the specified wildcard pattern pat.
 IRubyObject initialize(IRubyObject _newPath, Block unusedBlock)
          Creates a new Dir.
static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args)
          Creates the directory specified by path.
static IRubyObject open(IRubyObject recv, IRubyObject path, Block block)
          Returns a new directory object for path.
 IRubyObject path()
           
 IRubyObject read()
          Returns the next entry from this directory.
 IRubyObject rewind()
          Moves position in this directory to the first entry.
static IRubyObject rmdir(IRubyObject recv, IRubyObject path)
          Deletes the directory specified by path.
 IRubyObject seek(IRubyObject newPos)
          Moves to a position d.
 IRubyObject setPos(IRubyObject newPos)
           
 RubyInteger tell()
          Returns the current position in the directory.
 
Methods inherited from class org.jruby.RubyObject
addFinalizer, anyToString, asString, asSymbol, attachToObjectSpace, callInit, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethodMissingIfNecessary, callSuper, checkArrayType, checkFrozen, checkStringType, compilerCallMethod, compilerCallMethodWithIndex, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToString, convertToType, convertToType, convertToType, convertToTypeWithCheck, createObjectClass, dataGetStruct, dataWrapStruct, display, doClone, dup, eql, eqlInternal, equal, equalInternal, equals, evalSimple, evalUnder, evalWithBinding, extend, freeze, frozen, getInstanceVariable, getInstanceVariables, getInstanceVariablesSnapshot, getJavaClass, getMetaClass, getNativeTypeIndex, getRuntime, getSingletonClass, getSingletonClassClone, getType, hash, hashCode, id_deprecated, id, infectBy, inherited, initCopy, initialize_copy, initialize, inspect, instance_eval, instance_exec, instance_of, instance_variable_get, instance_variable_set, instance_variables, instanceVariableNames, isFalse, isFrozen, isImmediate, isKindOf, isNil, isSingleton, isTaint, isTrue, kind_of, makeMetaClass, match, method, methods, nil_p, obj_equal, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, respond_to, respondsTo, safeGetInstanceVariables, safeHasInstanceVariables, send, setFrozen, setInstanceVariable, setInstanceVariable, setInstanceVariables, setMetaClass, setTaint, singleton_methods, specificEval, taint, tainted, testFrozen, to_s, toString, trueFalseNil, trueFalseNil, type_deprecated, type, untaint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

dir

protected JRubyFile dir
Constructor Detail

RubyDir

public RubyDir(Ruby runtime,
               RubyClass type)
Method Detail

createDirClass

public static RubyClass createDirClass(Ruby runtime)

initialize

public IRubyObject initialize(IRubyObject _newPath,
                              Block unusedBlock)
Creates a new Dir. This method takes a snapshot of the contents of the directory at creation time, so changes to the contents of the directory will not be reflected during the lifetime of the Dir object returned, so a new Dir instance must be created to reflect changes to the underlying file system.


glob

public static IRubyObject glob(IRubyObject recv,
                               IRubyObject[] args,
                               Block block)
Returns an array of filenames matching the specified wildcard pattern pat. If a block is given, the array is iterated internally with each filename is passed to the block in turn. In this case, Nil is returned.


entries

public RubyArray entries()
Returns:
all entries for this Dir

entries

public static RubyArray entries(IRubyObject recv,
                                IRubyObject path)
Returns an array containing all of the filenames in the given directory.


chdir

public static IRubyObject chdir(IRubyObject recv,
                                IRubyObject[] args,
                                Block block)
Changes the current directory to path


chroot

public static IRubyObject chroot(IRubyObject recv,
                                 IRubyObject path)
Changes the root directory (only allowed by super user). Not available on all platforms.


rmdir

public static IRubyObject rmdir(IRubyObject recv,
                                IRubyObject path)
Deletes the directory specified by path. The directory must be empty.


foreach

public static IRubyObject foreach(IRubyObject recv,
                                  IRubyObject _path,
                                  Block block)
Executes the block once for each file in the directory specified by path.


getwd

public static RubyString getwd(IRubyObject recv)
Returns the current directory.


mkdir

public static IRubyObject mkdir(IRubyObject recv,
                                IRubyObject[] args)
Creates the directory specified by path. Note that the mode parameter is provided only to support existing Ruby code, and is ignored.


open

public static IRubyObject open(IRubyObject recv,
                               IRubyObject path,
                               Block block)
Returns a new directory object for path. If a block is provided, a new directory object is passed to the block, which closes the directory object before terminating.


close

public IRubyObject close()
Closes the directory stream.


each

public IRubyObject each(Block block)
Executes the block once for each entry in the directory.


tell

public RubyInteger tell()
Returns the current position in the directory.


seek

public IRubyObject seek(IRubyObject newPos)
Moves to a position d. pos must be a value returned by tell or 0.


setPos

public IRubyObject setPos(IRubyObject newPos)

path

public IRubyObject path()

read

public IRubyObject read()
Returns the next entry from this directory.


rewind

public IRubyObject rewind()
Moves position in this directory to the first entry.


getDir

protected static JRubyFile getDir(Ruby runtime,
                                  java.lang.String path,
                                  boolean mustExist)
Returns a Java File object for the specified path. If path is not a directory, throws IOError.

Parameters:
path - path for which to return the File object.
mustExist - is true the directory must exist. If false it must not.
Throws:
IOError - if path is not a directory.

getContents

protected static java.util.List getContents(java.io.File directory)
Returns the contents of the specified directory as an ArrayList containing the names of the files as Java Strings.


getContents

protected static java.util.List getContents(java.io.File directory,
                                            Ruby runtime)
Returns the contents of the specified directory as an ArrayList containing the names of the files as Ruby Strings.


getHomeDirectoryPath

public static IRubyObject getHomeDirectoryPath(IRubyObject recv,
                                               java.lang.String user)
Returns the home directory of the specified user on the system. If the home directory of the specified user cannot be found, an ArgumentError it thrown.


getHomeDirectoryPath

public static RubyString getHomeDirectoryPath(IRubyObject recv)


Copyright © 2002-2007 JRuby Team. All Rights Reserved.