Returns the last access time (a Time
object) for file, or epoch if file has not been accessed.
File.new("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
Returns the modification time for file.
File.new("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
Returns the change time for file (that is, the time directory information about the file was changed, not the file itself).
Note that on Windows (NTFS), returns creation time (birth time).
File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
Returns the birth time for file.
File.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003
If the platform doesn’t have birthtime, raises NotImplementedError
.
Returns true
if the named file exists and has a zero size.
file_name can be an IO
object.
Returns true
if the named file exists and has a zero size.
file_name can be an IO
object.
Returns true
if filepath
points to a character device, false
otherwise.
File.chardev?($stdin) # => true File.chardev?('t.txt') # => false
Returns true
if the named files are identical.
file_1 and file_2 can be an IO
object.
open("a", "w") {} p File.identical?("a", "a") #=> true p File.identical?("a", "./a") #=> true File.link("a", "b") p File.identical?("a", "b") #=> true File.symlink("a", "c") p File.identical?("a", "c") #=> true open("d", "w") {} p File.identical?("a", "d") #=> false
Creates a new File
object, via File.new
with the given arguments.
With no block given, returns the File
object.
With a block given, calls the block with the File
object and returns the block’s value.
Returns the hash of available encoding alias and original encoding name.
Encoding.aliases #=> {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1968"=>"US-ASCII", "SJIS"=>"Windows-31J", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}
Returns the receiver.
string = "my string" string.itself.object_id == string.object_id #=> true
Invokes the method identified by symbol, passing it any arguments specified. When the method is identified by a string, the string is converted to a symbol.
BasicObject
implements __send__
, Kernel
implements send
. __send__
is safer than send
when obj has the same method name like Socket
. See also public_send
.
class Klass def hello(*args) "Hello " + args.join(' ') end end k = Klass.new k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
Returns the previous value of global variable $!
, which may be nil
(see Global Variables):
begin raise('Boom 0') rescue => x0 puts "Exception: #{x0}; $!: #{$!}; cause: #{x0.cause.inspect}." begin raise('Boom 1') rescue => x1 puts "Exception: #{x1}; $!: #{$!}; cause: #{x1.cause}." begin raise('Boom 2') rescue => x2 puts "Exception: #{x2}; $!: #{$!}; cause: #{x2.cause}." end end end
Output:
Exception: Boom 0; $!: Boom 0; cause: nil. Exception: Boom 1; $!: Boom 1; cause: Boom 0. Exception: Boom 2; $!: Boom 2; cause: Boom 1.
Return the receiver associated with this KeyError
exception.
Return the receiver associated with this NameError
exception.
Return the arguments passed in as the third parameter to the constructor.
Return the receiver associated with this FrozenError
exception.
Return this SystemCallError’s error number.
Returns the list of Modules
nested at the point of call.
module M1 module M2 $a = Module.nesting end end $a #=> [M1::M2, M1] $a[0].name #=> "M1::M2"
In the first form, returns an array of the names of all constants accessible from the point of call. This list includes the names of all modules and classes defined in the global scope.
Module.constants.first(4) # => [:ARGF, :ARGV, :ArgumentError, :Array] Module.constants.include?(:SEEK_SET) # => false class IO Module.constants.include?(:SEEK_SET) # => true end
The second form calls the instance method constants
.
Returns a list of modules included/prepended in mod (including mod itself).
module Mod include Math include Comparable prepend Enumerable end Mod.ancestors #=> [Enumerable, Mod, Comparable, Math] Math.ancestors #=> [Math] Enumerable.ancestors #=> [Enumerable]
Returns an array of the names of the constants accessible in mod. This includes the names of constants in any included modules (example at start of section), unless the inherit parameter is set to false
.
The implementation makes no guarantees about the order in which the constants are yielded.
IO.constants.include?(:SYNC) #=> true IO.constants(false).include?(:SYNC) #=> false
Also see Module#const_defined?
.