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.

Version:
$Revision: 1.9 $
Author:
jvoegele

Field Summary
protected  java.io.File dir
           
protected  java.lang.String path
           
 
Fields inherited from class org.jruby.RubyObject
runtime
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyDir(Ruby ruby, RubyClass type)
           
 
Method Summary
static IRubyObject chdir(IRubyObject recv, RubyString path)
          Changes the current directory to path
static IRubyObject chroot(IRubyObject recv, RubyString path)
          Changes the root directory (only allowed by super user).
 IRubyObject close()
          Closes the directory stream.
static RubyClass createDirClass(Ruby ruby)
           
 IRubyObject each()
          Executes the block once for each entry in the directory.
static RubyArray entries(IRubyObject recv, RubyString path)
          Returns an array containing all of the filenames in the given directory.
static IRubyObject foreach(IRubyObject recv, RubyString path)
          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 ruby)
          Returns the contents of the specified directory as an ArrayList containing the names of the files as Ruby Strings.
protected static java.io.File getDir(Ruby ruby, java.lang.String path)
          Returns a Java File object for the specified path.
static RubyString getwd(IRubyObject recv)
          Returns the current directory.
static RubyArray glob(IRubyObject recv, RubyString pat)
          Returns an array of filenames matching the specified wildcard pattern pat.
 IRubyObject initialize(RubyString path)
          Creates a new Dir.
 boolean matches(java.lang.String str, java.lang.String pattern)
           
static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args)
          Creates the directory specified by path.
static IRubyObject newInstance(IRubyObject recv, IRubyObject[] args)
           
static IRubyObject open(IRubyObject recv, RubyString path)
          Returns a new directory object for path.
 RubyString read()
          Returns the next entry from this directory.
 IRubyObject rewind()
          Moves position in this directory to the first entry.
static IRubyObject rmdir(IRubyObject recv, RubyString path)
          Deletes the directory specified by path.
 IRubyObject seek(RubyFixnum pos)
          Moves to a position d.
 RubyInteger tell()
          Returns the current position in the directory.
 
Methods inherited from class org.jruby.RubyObject
argCount, asSymbol, callbackFactory, callInit, callMethod, callMethod, callMethod, checkSafeString, convertToString, convertToType, convertType, createObjectClass, defineSingletonMethod, display, dup, equal, equals, eval, eval, evalUnder, extend, extendObject, freeze, frozen, getInstanceVariable, getInstanceVariables, getJavaClass, getMetaClass, getRuntime, getSingletonClass, getType, hash, hashCode, hasInstanceVariable, id, infectBy, inspect, instance_eval, instance_of, instance_variables, instanceVariableNames, isFalse, isFrozen, isKindOf, isNil, isTaint, isTrue, kind_of, makeMetaClass, marshalTo, method_missing, method, methods, nilObject, private_methods, protected_methods, rbClone, removeInstanceVariable, respond_to, respondsTo, send, setFrozen, setInstanceVariable, setInstanceVariable, setInstanceVariables, setMetaClass, setTaint, setupClone, singleton_methods, singletonMethodsAllowed, specificEval, taint, tainted, to_a, to_s, toString, type, untaint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

path

protected java.lang.String path

dir

protected java.io.File dir
Constructor Detail

RubyDir

public RubyDir(Ruby ruby,
               RubyClass type)
Method Detail

createDirClass

public static RubyClass createDirClass(Ruby ruby)

newInstance

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

initialize

public IRubyObject initialize(RubyString path)
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 RubyArray glob(IRubyObject recv,
                             RubyString pat)
Returns an array of filenames matching the specified wildcard pattern pat.


entries

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


chdir

public static IRubyObject chdir(IRubyObject recv,
                                RubyString path)
Changes the current directory to path


chroot

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


rmdir

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


foreach

public static IRubyObject foreach(IRubyObject recv,
                                  RubyString path)
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,
                               RubyString path)
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()
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(RubyFixnum pos)
Moves to a position d. pos must be a value returned by tell or 0.


read

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


rewind

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


getDir

protected static java.io.File getDir(Ruby ruby,
                                     java.lang.String path)
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.
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 ruby)
Returns the contents of the specified directory as an ArrayList containing the names of the files as Ruby Strings.


matches

public boolean matches(java.lang.String str,
                       java.lang.String pattern)


Copyright © 2002 Jan Arne Petersen. All Rights Reserved.