Package org.jruby
Class RubyDir
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubyDir
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable,Cloneable,Comparable<IRubyObject>,InstanceVariables,InternalVariables,IRubyObject,CoreObjectType
The Ruby built-in class Dir.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String[]private static final String[]protected FileResourceprivate org.jcodings.Encoding(package private) static final ByteListprivate booleanprivate longprivate static final String[]private RubyStringprivate intprivate static final Patternprivate String[]private static final ByteListFields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATORFields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUST_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IRubyObjectaref(ThreadContext context, IRubyObject recv, IRubyObject[] args) private static RubyArrayasRubyStringList(Ruby runtime, List<ByteList> dirs) static IRubyObjectchdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Changes the current directory topathprivate final voidcheckDir()private final voidprivate static voidcheckDirIsTwoSlashesOnWindows(Ruby runtime, String path) children(ThreadContext context) Returns an array containing all of the filenames except for "." and ".." in the given directory.static RubyArraychildren(ThreadContext context, IRubyObject recv, IRubyObject arg) static RubyArraychildren(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) static IRubyObjectchroot(IRubyObject recv, IRubyObject path) Changes the root directory (only allowed by super user).final voidclose()close(ThreadContext context) Closes the directory stream.static RubyClasscreateDirClass(Ruby runtime) private static StringdirFromPath(String path, Ruby runtime) dirGlobs(ThreadContext context, String cwd, IRubyObject[] args, int flags) each(ThreadContext context, org.jcodings.Encoding enc, Block block) Executes the block once for each entry in the directory.each(ThreadContext context, Block block) Executes the block once for each entry in the directory.each(ThreadContext context, IRubyObject encOpts, Block block) each_child(ThreadContext context, org.jcodings.Encoding enc, Block block) Executes the block once for each child in the directory (i.e.each_child(ThreadContext context, Block block) Executes the block once for each child in the directory (i.e.static IRubyObjecteach_child(ThreadContext context, IRubyObject recv, IRubyObject arg, Block block) Executes the block once for each entry in the directory except for "." and "..", passing the filename of each entry as parameter to the block.static IRubyObjecteach_child(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject encOpts, Block block) Executes the block once for each entry in the directory except for "." and "..", passing the filename of each entry as parameter to the block.each19(ThreadContext context, Block block) Deprecated.each19(ThreadContext context, IRubyObject encoding, Block block) Deprecated.private static IRubyObjecteachChildCommon(ThreadContext context, IRubyObject recv, RubyString path, IRubyObject encOpts, Block block) static IRubyObjectempty_p(ThreadContext context, IRubyObject recv, IRubyObject arg) entries()static RubyArrayentries(IRubyObject recv, IRubyObject path) Deprecated.static RubyArrayentries(IRubyObject recv, IRubyObject path, IRubyObject arg, IRubyObject opts) Deprecated.static RubyArrayentries(ThreadContext context, IRubyObject recv, IRubyObject arg) Returns an array containing all of the filenames in the given directory.static RubyArrayentries(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) static RubyArrayentries19(ThreadContext context, IRubyObject recv, IRubyObject arg) Deprecated.static RubyArrayentries19(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) Deprecated.private static RubyArrayentriesCommon(ThreadContext context, IRubyObject path, org.jcodings.Encoding encoding, boolean childrenOnly) static IRubyObjectexist(ThreadContext context, IRubyObject recv, IRubyObject arg) static IRubyObjectexists_p(ThreadContext context, IRubyObject recv, IRubyObject arg) fileno(ThreadContext context) static IRubyObjectforeach(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Executes the block once for each file in the directory specified bypath.static IRubyObjectforeach(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject encOpts, Block block) static IRubyObjectforeach19(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Deprecated.static IRubyObjectforeach19(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject enc, Block block) Deprecated.private static IRubyObjectforeachCommon(ThreadContext context, IRubyObject recv, RubyString path, IRubyObject encOpts, Block block) getContents(FileResource directory) Deprecated.no longer usedprotected static List<RubyString>getContents(FileResource directory, Ruby runtime) Deprecated.no longer usedprivate static Stringprotected static FileResourceReturns a JavaFileobject for the specified path.protected static JRubyFilegetDirForRmdir(Ruby runtime, String path) Similar to getDir, but performs different checks to match rmdir behavior.private static org.jcodings.EncodinggetEncodingFromOpts(ThreadContext context, IRubyObject encOpts) private static String[]getEntries(ThreadContext context, FileResource dir, String path) private static FileResourcegetExistingDir(Ruby runtime, String path) static RubyStringgetHomeDirectoryPath(ThreadContext context) static IRubyObjectgetHomeDirectoryPath(ThreadContext context, String user) Returns the home directory of the specifieduseron the system.(package private) static RubyStringgetHomeDirectoryPath(ThreadContext context, IRubyObject home) getHomeFromEnv(Ruby runtime) getPath()static RubyStringgetwd(IRubyObject recv) Returns the current directory.static IRubyObjectglob(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Returns an array of filenames matching the specified wildcard patternpat.private static ByteListglobArgumentAsByteList(ThreadContext context, IRubyObject arg) private static StringglobOptions(ThreadContext context, IRubyObject[] args, int[] flags) static IRubyObjecthome(ThreadContext context, IRubyObject recv) Returns the home directory of the current user or the named user if given.static IRubyObjecthome(ThreadContext context, IRubyObject recv, IRubyObject user) static IRubyObjecthome(ThreadContext context, IRubyObject recv, IRubyObject[] args) Deprecated.initialize(ThreadContext context, IRubyObject path) Creates a newDir.initialize(ThreadContext context, IRubyObject path, IRubyObject encOpts) Likeinitialize(ThreadContext, IRubyObject)but accepts an :encoding option.initialize19(ThreadContext context, IRubyObject arg) Deprecated.private RubyDirinitializeCommon(ThreadContext context, IRubyObject pathArg, IRubyObject encOpts) inspect()rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.private static String[]list(FileResource directory) static IRubyObjectmkdir(IRubyObject recv, IRubyObject[] args) Deprecated.static IRubyObjectmkdir(ThreadContext context, IRubyObject recv, IRubyObject... args) Creates the directory specified bypath.static IRubyObjectmkdir19(ThreadContext context, IRubyObject recv, IRubyObject[] args) Deprecated.private static IRubyObjectmkdirCommon(Ruby runtime, String path, IRubyObject[] args) private static RubyArraynewEntryArray(Ruby runtime, String[] files, org.jcodings.Encoding encoding, boolean childrenOnly) private static RubyStringnewFilesystemString(Ruby runtime, String home) static IRubyObjectopen(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Returns a new directory object forpath.static IRubyObjectopen(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject encOpts, Block block) static IRubyObjectopen19(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Deprecated.path(ThreadContext context) rb_each_child(ThreadContext context, Block block) read()Returns the next entry from this directory.rewind()Moves position in this directory to the first entry.static IRubyObjectrmdir(IRubyObject recv, IRubyObject path) Deletes the directory specified bypath.static IRubyObjectrmdir19(ThreadContext context, IRubyObject recv, IRubyObject path) private static RubyFixnumrmdirCommon(Ruby runtime, String path) seek(IRubyObject newPos) Moves to a positiond.set_pos(IRubyObject newPos) tell()Returns the current position in the directory.to_path(ThreadContext context) <T> TConvert the object to the specified Java class, if possible.Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, dig, dig1, dig2, eqlInternal, equalInternal, equals, getNativeClassIndex, hashCode, inspect, op_eqq, puts, specificEval, toRubyString, toStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, defaultToJava, display, dup, ensureInstanceVariablesSettable, eql, eql_p, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, infectBy, infectBy, initialize, initialize_copy, initialize19, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method, method_missing, method_missing19, method19, methods, methods, methods19, methodsImpl, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal, op_equal_19, op_match, op_match19, op_not, op_not_equal, op_not_match, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, rbClone, rbInspect, recacheBuiltinMethods, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method_added, singleton_method_added19, singleton_method_removed, singleton_method_removed19, singleton_method_undefined, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, trust, type, type_deprecated, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
-
Field Details
-
path
-
dir
-
lastModified
private long lastModified -
snapshot
-
pos
private int pos -
isOpen
private boolean isOpen -
encoding
private org.jcodings.Encoding encoding -
PROTOCOL_PATTERN
-
BASE
-
BASE_FLAGS
-
NO_FILES
-
HOME
-
user_home
-
-
Constructor Details
-
RubyDir
-
-
Method Details
-
createDirClass
-
checkDir
private final void checkDir() -
checkDirIgnoreClosed
private final void checkDirIgnoreClosed() -
initialize
Creates a newDir. 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 theDirobject returned, so a newDirinstance must be created to reflect changes to the underlying file system.- Parameters:
context- current contextpath- target path- Returns:
- a new Dir object
-
initialize
Likeinitialize(ThreadContext, IRubyObject)but accepts an :encoding option.- Parameters:
context- current contextpath- target pathencOpts- encoding options- Returns:
- a new Dir object
-
initializeCommon
-
initialize19
Deprecated. -
dirGlobs
private static ArrayList<ByteList> dirGlobs(ThreadContext context, String cwd, IRubyObject[] args, int flags) -
asRubyStringList
-
getCWD
-
globOptions
-
aref
-
globArgumentAsByteList
-
glob
public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Returns an array of filenames matching the specified wildcard patternpat. 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
- Returns:
- all entries for this Dir
-
entries
Returns an array containing all of the filenames in the given directory. -
entries
public static RubyArray entries(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) -
entriesCommon
private static RubyArray entriesCommon(ThreadContext context, IRubyObject path, org.jcodings.Encoding encoding, boolean childrenOnly) -
newEntryArray
-
getEntries
-
checkDirIsTwoSlashesOnWindows
-
chdir
public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Changes the current directory topath -
chroot
Changes the root directory (only allowed by super user). Not available on all platforms. -
children
Returns an array containing all of the filenames except for "." and ".." in the given directory. -
children
-
children
public static RubyArray children(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) -
rmdir
Deletes the directory specified bypath. The directory must be empty. -
rmdir19
-
rmdirCommon
-
each_child
public static IRubyObject each_child(ThreadContext context, IRubyObject recv, IRubyObject arg, Block block) Executes the block once for each entry in the directory except for "." and "..", passing the filename of each entry as parameter to the block. -
each_child
public static IRubyObject each_child(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject encOpts, Block block) Executes the block once for each entry in the directory except for "." and "..", passing the filename of each entry as parameter to the block. -
foreach
public static IRubyObject foreach(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Executes the block once for each file in the directory specified bypath. -
foreach
public static IRubyObject foreach(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject encOpts, Block block) -
getEncodingFromOpts
private static org.jcodings.Encoding getEncodingFromOpts(ThreadContext context, IRubyObject encOpts) -
eachChildCommon
private static IRubyObject eachChildCommon(ThreadContext context, IRubyObject recv, RubyString path, IRubyObject encOpts, Block block) -
foreachCommon
private static IRubyObject foreachCommon(ThreadContext context, IRubyObject recv, RubyString path, IRubyObject encOpts, Block block) -
getwd
Returns the current directory. -
home
Returns the home directory of the current user or the named user if given. -
home
-
mkdir
Creates the directory specified bypath. Note that themodeparameter is provided only to support existing Ruby code, and is ignored. -
mkdir
Deprecated. -
mkdir19
@Deprecated public static IRubyObject mkdir19(ThreadContext context, IRubyObject recv, IRubyObject[] args) Deprecated. -
mkdirCommon
-
open
public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Returns a new directory object forpath. If a block is provided, a new directory object is passed to the block, which closes the directory object before terminating. -
open
public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject encOpts, Block block) -
open19
@Deprecated public static IRubyObject open19(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Deprecated. -
close
Closes the directory stream. -
close
public final void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
each
Executes the block once for each entry in the directory. -
each
Executes the block once for each entry in the directory. -
each
-
each19
Deprecated. -
each19
Deprecated. -
each_child
Executes the block once for each child in the directory (i.e. all the directory entries except for "." and ".."). -
each_child
Executes the block once for each child in the directory (i.e. all the directory entries except for "." and ".."). -
rb_each_child
-
inspect
Description copied from class:RubyBasicObjectrb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"- Specified by:
inspectin interfaceIRubyObject- Overrides:
inspectin classRubyBasicObject- Returns:
- String
-
tell
Returns the current position in the directory. -
seek
Moves to a positiond.posmust be a value returned bytellor 0. -
set_pos
-
path
-
to_path
-
getPath
-
read
Returns the next entry from this directory. -
rewind
Moves position in this directory to the first entry. -
empty_p
-
exist
-
exists_p
-
fileno
-
getDir
Returns a JavaFileobject for the specified path. Ifpathis not a directory, throwsIOError.- Parameters:
path- path for which to return theFileobject.mustExist- is true the directory must exist. If false it must not.
-
getExistingDir
-
getDirForRmdir
Similar to getDir, but performs different checks to match rmdir behavior.- Parameters:
runtime-path-- Returns:
-
dirFromPath
- Throws:
RaiseException
-
list
-
getContents
Deprecated.no longer used -
getContents
Deprecated.no longer used -
getHomeDirectoryPath
Returns the home directory of the specifieduseron the system. If the home directory of the specified user cannot be found, anArgumentError it thrown. -
newFilesystemString
-
getHomeDirectoryPath
-
getHomeFromEnv
-
getHomeDirectoryPath
-
toJava
Description copied from interface:IRubyObjectConvert the object to the specified Java class, if possible.- Specified by:
toJavain interfaceIRubyObject- Overrides:
toJavain classRubyBasicObject- Parameters:
target- The target type to which the object should be converted.- See Also:
-
entries19
@Deprecated public static RubyArray entries19(ThreadContext context, IRubyObject recv, IRubyObject arg) Deprecated. -
entries19
@Deprecated public static RubyArray entries19(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) Deprecated. -
home
@Deprecated public static IRubyObject home(ThreadContext context, IRubyObject recv, IRubyObject[] args) Deprecated. -
foreach19
@Deprecated public static IRubyObject foreach19(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Deprecated. -
foreach19
@Deprecated public static IRubyObject foreach19(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject enc, Block block) Deprecated. -
entries
Deprecated. -
entries
@Deprecated public static RubyArray entries(IRubyObject recv, IRubyObject path, IRubyObject arg, IRubyObject opts) Deprecated.
-