Deletes the named files, returning the number of names passed as arguments. Raises an exception on any error. See also Dir::rmdir
.
Returns the last access time (a Time
object)
for <i>file</i>, or epoch if <i>file</i> 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 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 is a directory, or a symlink that points at a directory, and false
otherwise.
file_name can be an IO
object.
File.directory?(".")
Returns true
if the named file has the sticky bit set.
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
Returns a string which represents the encoding for programmers.
Encoding::UTF_8.inspect #=> "#<Encoding:UTF-8>" Encoding::ISO_2022_JP.inspect #=> "#<Encoding:ISO-2022-JP (dummy)>"
Creates a printable version of e.
mathn serves to make mathematical operations more precise in Ruby and to integrate other mathematical standard libraries.
Without mathn:
3 / 2 => 1 # Integer
With mathn:
3 / 2 => 3/2 # Rational
mathn keeps value in exact terms.
Without mathn:
20 / 9 * 3 * 14 / 7 * 3 / 2 # => 18
With mathn:
20 / 9 * 3 * 14 / 7 * 3 / 2 # => 20
When you require ‘mathn’, the libraries for Prime
, CMath
, Matrix
and Vector
are also loaded.
Author: Keiju ISHITSUKA (SHL Japan Inc.)
provides a unified clone
operation, for REXML::XPathParser
to use across multiple Object
types
Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. clone
copies the frozen and tainted state of obj. See also the discussion under Object#dup
.
class Klass attr_accessor :str end s1 = Klass.new #=> #<Klass:0x401b3a38> s1.str = "Hello" #=> "Hello" s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello"> s2.str[1,4] = "i" #=> "i" s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">" s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
This method may have class-specific behavior. If so, that behavior will be documented under the #initialize_copy
method of the class.
Deprecated method that is equivalent to taint
.
Deprecated method that is equivalent to tainted?
.
Returns a string containing a human-readable representation of obj. The default inspect
shows the object’s class name, an encoding of the object id, and a list of the instance variables and their values (by calling inspect
on each of them). User defined classes should override this method to provide a better representation of obj. When overriding this method, it should return a string whose encoding is compatible with the default external encoding.
[ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "2008-03-08 19:43:39 +0900" class Foo end Foo.new.inspect #=> "#<Foo:0x0300c868>" class Bar def initialize @bar = 1 end end Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
Return this exception’s class name and message
Round to the nearest integer (by default), returning the result as a BigDecimal
.
BigDecimal('3.14159').round #=> 3 BigDecimal('8.7').round #=> 9 BigDecimal('-9.9').round #=> -10
If n is specified and positive, the fractional part of the result has no more than that many digits.
If n is specified and negative, at least that many digits to the left of the decimal point will be 0 in the result.
BigDecimal('3.14159').round(3) #=> 3.142 BigDecimal('13345.234').round(-2) #=> 13300.0
The value of the optional mode argument can be used to determine how rounding is performed; see BigDecimal.mode
.
Returns self if the value is non-zero, nil otherwise.
Returns debugging information about the value as a string of comma-separated values in angle brackets with a leading #:
BigDecimal.new("1234.5678").inspect #=> "#<BigDecimal:b7ea1130,'0.12345678E4',8(12)>"
The first part is the address, the second is the value as a string, and the final part ss(mm) is the current number of significant digits and the maximum number of significant digits, respectively.
Returns the exponent of the BigDecimal
number, as an Integer
.
If the number can be represented as 0.xxxxxx*10**n where xxxxxx is a string of digits with no leading zeros, then n is the exponent.
Iterates the given block int
times, passing in values from zero to int - 1
.
If no block is given, an Enumerator
is returned instead.
5.times do |i| print i, " " end #=> 0 1 2 3 4
Rounds int
to a given precision in decimal digits (default 0 digits).
Precision may be negative. Returns a floating point number when ndigits
is positive, self
for zero, and round down for negative.
1.round #=> 1 1.round(2) #=> 1.0 15.round(-1) #=> 20
Returns the truncated value (toward the nearest integer; 0.5 => 1; -0.5 => -1).
Rational(3).round #=> 3 Rational(2, 3).round #=> 1 Rational(-3, 2).round #=> -2 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 '%f' % Rational('-123.456').round(+1) #=> "-123.500000" '%f' % Rational('-123.456').round(-1) #=> "-120.000000"