Module: FileTest
Overview
FileTest implements file test operations similar to those used in
::File::Stat. It exists as a standalone module, and its methods are
also insinuated into the ::File class. (Note that this is not done
by inclusion: the interpreter cheats).
Instance Attribute Summary
-
#directory?(dirpath) ⇒ Boolean
readonly
Alias for File.directory?.
Instance Method Summary
-
#blockdev?(object) ⇒ Boolean
Alias for File.blockdev?.
-
#chardev?(object) ⇒ Boolean
Alias for File.chardev?.
-
#empty?(object) ⇒ Boolean
Alias for File.empty?.
-
#executable?(path) ⇒ Boolean
Alias for File.executable?.
-
#executable_real?(path) ⇒ Boolean
Alias for File.executable_real?.
-
#exist?(object) ⇒ Boolean
Alias for File.exist?.
-
#file?(object) ⇒ Boolean
Alias for File.file?.
-
#grpowned?(object) ⇒ Boolean
Alias for File.grpowned?.
-
#identical?(object_0, object_1) ⇒ Boolean
Alias for File.identical?.
-
#owned?(object) ⇒ Boolean
Alias for File.owned?.
-
#pipe?(path) ⇒ Boolean
Alias for File.pipe?.
-
#readable?(path) ⇒ Boolean
Alias for File.readable?.
-
#readable_real?(path) ⇒ Boolean
Alias for File.readable_real?.
-
#setgid?(object) ⇒ Boolean
Alias for File.setgid?.
-
#setuid?(object) ⇒ Boolean
Alias for File.setuid?.
-
#size(object) ⇒ Integer
Alias for File.size.
-
#size?(object) ⇒ Integer?
Alias for File.size?.
-
#socket?(object) ⇒ Boolean
Alias for File.socket?.
-
#sticky?(object) ⇒ Boolean
Alias for File.sticky?.
-
#symlink?(path) ⇒ Boolean
Alias for File.symlink?.
-
#world_readable?(object) ⇒ Integer?
Alias for File.world_readable?.
-
#world_writable?(object) ⇒ Integer?
Alias for File.world_writable?.
-
#writable?(object) ⇒ Boolean
Alias for File.writable?.
-
#writable_real?(object) ⇒ Boolean
Alias for File.writable_real?.
-
#zero?(object) ⇒ Boolean
Alias for File.zero?.
Instance Attribute Details
#directory?(dirpath) ⇒ Boolean (readonly)
Alias for File.directory?. 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?.
Instance Method Details
#blockdev?(object) ⇒ Boolean
Alias for File.blockdev?.
#chardev?(object) ⇒ Boolean
Alias for File.chardev?.
#empty?(object) ⇒ Boolean
Alias for File.empty?.
Returns whether the given object exists and has size zero.
The given object may be the path to a file:
filepath = '/tmp/t.tmp'
File.write(filepath, 'foo') # File has non-zero size.
File.zero?(filepath) # => false
File.truncate(filepath, 0) # File has zero size.
File.zero?(filepath) # => true
File.delete(filepath) # Clean up.
The given object may be the path to a directory:
dirpath = '/tmp/foo'
Dir.mkdir(dirpath)
Dir.new(dirpath).children.size # => 0
#### Size is filesystem-dependent; may or may not be zero.
File.size(dirpath) # => 4096
File.zero?(dirpath) # => false
filepath = '/tmp/foo/t.tmp' # => "/tmp/foo/t.tmp"
File.write(filepath, 'foo') # Add a child.
Dir.new(dirpath).children.size # => 1
File.size(dirpath) # => 4096
File.zero?(dirpath) # => false
FileUtils.rm_rf(dirpath) # Clean up.
The given object may be an IO object:
File.zero?($stdin) # => true
The given object may be none of the above:
File.zero?('nosuch') # => false
#executable?(path) ⇒ Boolean
Alias for File.executable?.
#executable_real?(path) ⇒ Boolean
Alias for File.executable_real?.
#exist?(object) ⇒ Boolean
Alias for File.exist?.
#file?(object) ⇒ Boolean
Alias for File.file?.
#grpowned?(object) ⇒ Boolean
Alias for File.grpowned?.
#identical?(object_0, object_1) ⇒ Boolean
Alias for File.identical?.
#owned?(object) ⇒ Boolean
Alias for File.owned?.
#pipe?(path) ⇒ Boolean
Alias for File.pipe?.
#readable?(path) ⇒ Boolean
Alias for File.readable?.
#readable_real?(path) ⇒ Boolean
Alias for File.readable_real?.
#setgid?(object) ⇒ Boolean
Alias for File.setgid?.
#setuid?(object) ⇒ Boolean
Alias for File.setuid?.
#size(object) ⇒ Integer
Alias for File.size.
#size?(object) ⇒ Integer?
Alias for File.size?.
#socket?(object) ⇒ Boolean
Alias for File.socket?.
#sticky?(object) ⇒ Boolean
Alias for File.sticky?.
#symlink?(path) ⇒ Boolean
Alias for File.symlink?.
#world_readable?(object) ⇒ Integer?
Alias for File.world_readable?.
#world_writable?(object) ⇒ Integer?
Alias for File.world_writable?.
#writable?(object) ⇒ Boolean
Alias for File.writable?.
#writable_real?(object) ⇒ Boolean
Alias for File.writable_real?.
#zero?(object) ⇒ Boolean
Alias for File.zero?.