Reads and returns the next entry name from self
; returns nil
if at end-of-stream; see Dir As Stream-Like:
dir = Dir.new('example') dir.read # => "." dir.read # => ".." dir.read # => "config.h"
Returns an array of the entry names in self
except for '.'
and '..'
:
dir = Dir.new('/example') dir.children # => ["config.h", "lib", "main.rb"]
Sets the position in self
to zero; see Dir As Stream-Like:
dir = Dir.new('example') dir.read # => "." dir.read # => ".." dir.pos # => 2 dir.rewind # => #<Dir:example> dir.pos # => 0
Returns whether dirpath
is a directory in the underlying file system:
Dir.exist?('/example') # => true Dir.exist?('/nosuch') # => false Dir.exist?('/example/main.rb') # => false
Same as File.directory?
.
Returns a File::Stat
object for the file at filepath
(see File::Stat
):
File.stat('t.txt').class # => File::Stat
Like File::stat
, but does not follow the last symbolic link; instead, returns a File::Stat
object for the link itself.
File.symlink('t.txt', 'symlink') File.stat('symlink').size # => 47 File.lstat('symlink').size # => 5
Returns the name of the file referenced by the given link. Not available on all platforms.
File.symlink("testfile", "link2test") #=> 0 File.readlink("link2test") #=> "testfile"
Renames the given file to the new name. Raises a SystemCallError
if the file cannot be renamed.
File.rename("afile", "afile.bak") #=> 0
Returns the real (absolute) pathname of pathname in the actual filesystem not containing symlinks or useless dots.
If dir_string is given, it is used as a base directory for interpreting relative pathname instead of the current directory.
All components of the pathname must exist when this method is called.
Returns the real (absolute) pathname of pathname in the actual filesystem. The real pathname doesn’t contain symlinks or useless dots.
If dir_string is given, it is used as a base directory for interpreting relative pathname instead of the current directory.
The last component of the real pathname can be nonexistent.
Like File#stat
, but does not follow the last symbolic link; instead, returns a File::Stat
object for the link itself:
File.symlink('t.txt', 'symlink') f = File.new('symlink') f.stat.size # => 47 f.lstat.size # => 11
Return true
if the named file exists.
file_name can be an IO
object.
“file exists” means that stat() or fstat() system call is successful.
Returns true
if the named file is readable by the effective user and group id of this process. See eaccess(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the effective user/group.
Returns the list of loaded encodings.
Encoding.list #=> [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>, #<Encoding:ISO-2022-JP (dummy)>] Encoding.find("US-ASCII") #=> #<Encoding:US-ASCII> Encoding.list #=> [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>, #<Encoding:US-ASCII>, #<Encoding:ISO-2022-JP (dummy)>]
Rewinds the enumeration sequence to the beginning.
If the enclosed object responds to a “rewind” method, it is called.
Returns the return value of the iterator.
o = Object.new def o.each yield 1 yield 2 yield 3 100 end e = o.to_enum puts e.next #=> 1 puts e.next #=> 2 puts e.next #=> 3 begin e.next rescue StopIteration => ex puts ex.result #=> 100 end
Returns a Digest
subclass by name
in a thread-safe manner even when on-demand loading is involved.
require 'digest' Digest("MD5") # => Digest::MD5 Digest(:SHA256) # => Digest::SHA256 Digest(:Foo) # => LoadError: library not found for class Digest::Foo -- digest/foo
Prevents further modifications to obj. A FrozenError
will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object#frozen?
.
This method returns self.
a = [ "a", "b", "c" ] a.freeze a << "z"
produces:
prog.rb:3:in `<<': can't modify frozen Array (FrozenError) from prog.rb:3
Objects of the following classes are always frozen: Integer
, Float
, Symbol
.
Returns a string representing obj. The default to_s
prints the object’s class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby
programs returns “main”.
Returns a string representation of self
:
x = RuntimeError.new('Boom') x.to_s # => "Boom" x = RuntimeError.new x.to_s # => "RuntimeError"
Return the status value associated with this system exit.
Return the receiver associated with this KeyError
exception.
Return the receiver associated with this NameError
exception.