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.
- Author:
- jvoegele
- 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
FieldsFields 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, 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) chdir(ThreadContext context, Block block) static IRubyObjectchdir(ThreadContext context, IRubyObject recv, Block block) Changes the current directory topathstatic IRubyObjectchdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Deprecated.static IRubyObjectchdir(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Changes the current directory topathchildren(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) Deprecated.static IRubyObjectchroot(ThreadContext context, IRubyObject recv, IRubyObject path) Changes the root directory (only allowed by super user).final voidclose()Deprecated.close(ThreadContext context) Closes the directory stream.static RubyClasscreateDirClass(ThreadContext context, RubyClass Object, RubyModule Enumerable) 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.static IRubyObjectempty_p(ThreadContext context, IRubyObject recv, IRubyObject path) entries()Deprecated.static RubyArrayentries(IRubyObject recv, IRubyObject path) Deprecated.static RubyArrayentries(IRubyObject recv, IRubyObject path, IRubyObject arg, IRubyObject opts) Deprecated.entries(ThreadContext context) 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 IRubyObjectexist(ThreadContext context, IRubyObject recv, IRubyObject arg) static IRubyObjectexists_p(ThreadContext context, IRubyObject recv, IRubyObject arg) Deprecated.static IRubyObjectfchdir(ThreadContext context, IRubyObject dirClass, IRubyObject ignored) fileno(ThreadContext context) static IRubyObjectfor_fd(ThreadContext context, IRubyObject recv, IRubyObject ignored) 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) getContents(FileResource directory) Deprecated.no longer usedprotected static List<RubyString> getContents(FileResource directory, Ruby runtime) Deprecated.no longer usedprotected 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.static RubyStringgetHomeDirectoryPath(ThreadContext context) static IRubyObjectgetHomeDirectoryPath(ThreadContext context, String user) Returns the home directory of the specifieduseron the system.getHomeFromEnv(Ruby runtime) getPath()static RubyStringgetwd(IRubyObject recv) Deprecated.static RubyStringgetwd(ThreadContext context, 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.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.inspect(ThreadContext context) Returns a string containing a human-readable representation of obj.static IRubyObjectmkdir(IRubyObject recv, IRubyObject[] args) Deprecated.static IRubyObjectmkdir(ThreadContext context, IRubyObject recv, IRubyObject... args) Creates the directory specified bypath.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) path(ThreadContext context) rb_each_child(ThreadContext context, Block block) read()Deprecated.read(ThreadContext context) Returns the next entry from this directory.rewind()Deprecated.rewind(ThreadContext context) Moves position in this directory to the first entry.static IRubyObjectrmdir(IRubyObject recv, IRubyObject path) Deprecated.static IRubyObjectrmdir(ThreadContext context, IRubyObject recv, IRubyObject path) Deletes the directory specified bypath.static IRubyObjectrmdir19(IRubyObject recv, IRubyObject path) Deprecated.seek(IRubyObject newPos) Deprecated.seek(ThreadContext context, IRubyObject newPos) Moves to a positiond.set_pos(IRubyObject newPos) Deprecated.set_pos(ThreadContext context, IRubyObject newPos) tell()Deprecated.tell(ThreadContext context) 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, dig, dig1, dig2, eqlInternal, equalInternal, equals, finishObjectClass, getNativeClassIndex, hashCode, inspect, op_eqq, puts, specificEval, toRubyString, toStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, cloneSetup, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, display, dup, dupFinalizer, dupSetup, ensureInstanceVariablesSettable, eql, eql_p, eql_p, equal_p, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, finishBasicObjectClass, forEachInstanceVariable, forEachInstanceVariableName, freeze, frozen_p, getCurrentContext, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMarshalVariableList, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize_copy, initialize_copy, inspect, inspectHashCode, 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, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, makeMetaClass, makeMetaClassBootstrap, method, method, method, method_missing, methods, methods, nil_p, nonFixnumHashCode, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal, op_match, op_not, op_not_equal, op_not_match, private_methods, protected_methods, public_methods, rbClone, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method, singleton_method_added, singleton_method_removed, singleton_method_undefined, singleton_methods, singletonClass, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, to_s, trust, type, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariables
-
Field Details
-
dir
-
-
Constructor Details
-
RubyDir
-
-
Method Details
-
createDirClass
public static RubyClass createDirClass(ThreadContext context, RubyClass Object, RubyModule Enumerable) -
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
-
aref
-
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
Deprecated. -
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) -
chdir
public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject path, Block block) Changes the current directory topath -
chdir
Changes the current directory topath -
fchdir
-
chdir
-
chroot
Deprecated. -
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
Deprecated. -
rmdir19
Deprecated. -
rmdir
Deletes the directory specified bypath. The directory must be empty. -
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) -
getwd
Deprecated. -
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. -
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) -
close
Closes the directory stream. -
close
Deprecated.- 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
-
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:RubyBasicObjectReturns 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
-
tell
Returns the current position in the directory. -
tell
Deprecated. -
seek
Deprecated. -
seek
Moves to a positiond.posmust be a value returned bytellor 0. -
set_pos
Deprecated. -
set_pos
-
path
-
to_path
-
getPath
-
read
Deprecated. -
read
Returns the next entry from this directory. -
rewind
Deprecated. -
rewind
Moves position in this directory to the first entry. -
empty_p
-
exist
-
exists_p
@Deprecated(since="10.0") public static IRubyObject exists_p(ThreadContext context, IRubyObject recv, IRubyObject arg) Deprecated. -
fileno
-
for_fd
-
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.
-
getDirForRmdir
Similar to getDir, but performs different checks to match rmdir behavior.- Parameters:
runtime-path-- Returns:
-
getContents
Deprecated.no longer used -
getContents
@Deprecated(since="9.4-") protected static List<RubyString> getContents(FileResource directory, Ruby runtime) 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. -
getHomeDirectoryPath
-
getHomeFromEnv
-
toJava
Description copied from interface:IRubyObjectConvert the object to the specified Java class, if possible.- Specified by:
toJavain interfaceIRubyObject- Overrides:
toJavain classRubyBasicObject- Type Parameters:
T- type- Parameters:
target- The target type to which the object should be converted.- Returns:
- java type
- See Also:
-
home
@Deprecated public static IRubyObject home(ThreadContext context, IRubyObject recv, IRubyObject[] args) Deprecated. -
entries
Deprecated. -
entries
@Deprecated public static RubyArray entries(IRubyObject recv, IRubyObject path, IRubyObject arg, IRubyObject opts) Deprecated. -
chdir
@Deprecated public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Deprecated.
-