org.jruby
Class RubyDir

java.lang.Object
  extended by org.jruby.RubyObject
      extended by org.jruby.RubyDir
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType

public class RubyDir
extends RubyObject

.The Ruby built-in class Dir.

Author:
jvoegele
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Finalizer, RubyObject.ObjectMethods, RubyObject.VariableTableEntry
 
Field Summary
protected  JRubyFile dir
           
 
Fields inherited from class org.jruby.RubyObject
ALL_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, OBJECT_ALLOCATOR, TAINTED_F, UNDEF, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, VARIABLE_TABLE_DEFAULT_CAPACITY, VARIABLE_TABLE_EMPTY_TABLE, VARIABLE_TABLE_LOAD_FACTOR, VARIABLE_TABLE_MAXIMUM_CAPACITY, variableTable, variableTableSize, variableTableThreshold
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyDir(Ruby runtime, RubyClass type)
           
 
Method Summary
static IRubyObject aref(IRubyObject recv, IRubyObject[] args)
           
static IRubyObject chdir(ThreadContext context, 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(ThreadContext context, 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(ThreadContext context, IRubyObject recv, IRubyObject _path, Block block)
          Executes the block once for each file in the directory specified by path.
protected static java.util.List<java.lang.String> 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<RubyString> 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(ThreadContext context)
           
static IRubyObject getHomeDirectoryPath(ThreadContext context, 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(ThreadContext context, 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(ThreadContext context, IRubyObject recv, IRubyObject path, Block block)
          Returns a new directory object for path.
 IRubyObject path(ThreadContext context)
           
 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 set_pos(IRubyObject newPos)
           
 RubyInteger tell()
          Returns the current position in the directory.
 
Methods inherited from class org.jruby.RubyObject
addFinalizer, anyToString, as, asJavaString, asString, attachToObjectSpace, callInit, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkFrozen, checkStringType, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToString, convertToType, copySpecialInstanceVariables, createObjectClass, dataGetStruct, dataWrapStruct, display, dup, ensureInstanceVariablesSettable, eql_p, eql, eqlInternal, equal_p, equalInternal, equals, evalUnder, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFlag, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariableList, getInternalVariables, getJavaClass, getMetaClass, getNativeTypeIndex, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariableCount, getVariableList, getVariableMap, getVariableNameList, hash, hashCode, hasInstanceVariable, hasInternalVariable, hasVariables, id_deprecated, id, infectBy, initialize_copy, initialize, inspect, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isRubyVariable, isTaint, isTrue, kind_of_p, makeMetaClass, method, methods, nil_p, op_eqq, op_equal, op_match, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, send, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, singleton_methods, specificEval, specificEval, specificEval, specificEval, specificEval, syncVariables, taint, tainted_p, testFrozen, to_a, to_java, to_s, toString, type_deprecated, type, untaint, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableGetMap, variableTableGetMap, variableTableGetSize, variableTableGetTable, variableTableReadLocked, variableTableRehash, variableTableRemove, variableTableStore, variableTableSync
 
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.


aref

public static IRubyObject aref(IRubyObject recv,
                               IRubyObject[] args)

glob

public static IRubyObject glob(ThreadContext context,
                               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(ThreadContext context,
                                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(ThreadContext context,
                                  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(ThreadContext context,
                               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(ThreadContext context,
                        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.


set_pos

public IRubyObject set_pos(IRubyObject newPos)

path

public IRubyObject path(ThreadContext context)

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<java.lang.String> 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<RubyString> 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(ThreadContext context,
                                               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(ThreadContext context)


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