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.
Changes permission bits on file to the bit pattern represented by mode_int. Actual effects are platform dependent; on Unix systems, see chmod(2)
for details. Follows symbolic links. Also see File#lchmod
.
f = File.new("out", "w"); f.chmod(0644) #=> 0
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 is readable by the effective user and group id of this process. See eaccess(3).
Returns true
if the named file exists and has a zero size.
file_name can be an IO
object.
Returns a replicated encoding of enc whose name is name. The new encoding should have the same byte structure of enc. If name is used by another encoding, raise ArgumentError
.
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
Invokes Module.prepend_features
on each parameter in reverse order.
Callback invoked whenever the receiver is included in another module or class. This should be used in preference to Module.append_features
if your code wants to perform some action when a module is included in another.
module A def A.included(mod) puts "#{self} included in #{mod}" end end module Enumerable include A end # => prints "A included in Enumerable"
Controls handling of arithmetic exceptions and rounding. If no value is supplied, the current value is returned.
Six values of the mode parameter control the handling of arithmetic exceptions:
BigDecimal::EXCEPTION_NaN
BigDecimal::EXCEPTION_INFINITY
BigDecimal::EXCEPTION_UNDERFLOW
BigDecimal::EXCEPTION_OVERFLOW
BigDecimal::EXCEPTION_ZERODIVIDE
BigDecimal::EXCEPTION_ALL
For each mode parameter above, if the value set is false, computation continues after an arithmetic exception of the appropriate type. When computation continues, results are as follows:
EXCEPTION_NaN
NaN
EXCEPTION_INFINITY
+Infinity or -Infinity
EXCEPTION_UNDERFLOW
0
EXCEPTION_OVERFLOW
+Infinity or -Infinity
EXCEPTION_ZERODIVIDE
+Infinity or -Infinity
One value of the mode parameter controls the rounding of numeric values: BigDecimal::ROUND_MODE
. The values it can take are:
ROUND_UP
, :up
round away from zero
ROUND_DOWN
, :down, :truncate
round towards zero (truncate)
ROUND_HALF_UP
, :half_up, :default
round towards the nearest neighbor, unless both neighbors are equidistant, in which case round away from zero. (default)
ROUND_HALF_DOWN
, :half_down
round towards the nearest neighbor, unless both neighbors are equidistant, in which case round towards zero.
ROUND_HALF_EVEN
, :half_even, :banker
round towards the nearest neighbor, unless both neighbors are equidistant, in which case round towards the even neighbor (Banker’s rounding)
ROUND_CEILING
, :ceiling, :ceil
round towards positive infinity (ceil)
ROUND_FLOOR
, :floor
round towards negative infinity (floor)
Returns the BigDecimal
version number.
Returns an Array of two Integer
values.
The first value is the current number of significant digits in the BigDecimal
. The second value is the maximum number of significant digits for the BigDecimal
.
BigDecimal('5').precs #=> [9, 18]
Divides by the specified value, and returns the quotient and modulus as BigDecimal
numbers. The quotient is rounded towards negative infinity.
For example:
require 'bigdecimal' a = BigDecimal.new("42") b = BigDecimal.new("9") q, m = a.divmod(b) c = q * b + m a == c #=> true
The quotient q is (a/b).floor, and the modulus is the amount that must be added to q * b to get a.
Returns true
if rat
is greater than 0.
Returns true
if rat
is less than 0.
Returns a hash of parsed elements.
Creates a new Date
object by parsing from a string according to some typical XML
Schema formats.
Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
Returns true if the date is on or after the day of calendar reform.
Date.new(1582,10,15).gregorian? #=> true (Date.new(1582,10,15) - 1).gregorian? #=> false
This method is equivalent to new_start
(Date::GREGORIAN
).
This method is equivalent to strftime(‘%F’).
Creates a new DateTime
object by parsing from a string according to some typical XML
Schema formats.
DateTime.xmlschema('2001-02-03T04:05:06+07:00') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>