Returns the original line from source for from the given object
.
See ::trace_object_allocations
for more information and examples.
Returns the number of malloc() allocations.
Only available if ruby was built with CALC_EXACT_MALLOC_SIZE
.
Returns true if the method mid
have an option opt
.
p FileUtils.have_option?(:cp, :noop) #=> true p FileUtils.have_option?(:rm, :force) #=> true p FileUtils.have_option?(:rm, :preserve) #=> false
Returns an Array
of option names of the method mid
.
p FileUtils.options_of(:rm) #=> ["noop", "verbose", "force"]
Returns whether or not the function func
can be found in the common header files, or within any headers
that you provide. If found, a macro is passed as a preprocessor constant to the compiler using the function name, in uppercase, prepended with HAVE_
.
To check functions in an additional library, you need to check that library first using have_library()
. The func
shall be either mere function name or function name with arguments.
For example, if have_func('foo')
returned true
, then the HAVE_FOO
preprocessor macro would be passed to the compiler.
Returns an array containing the quotient and modulus obtained by dividing num
by numeric
.
If q, r = x.divmod(y)
, then
q = floor(x/y) x = q*y + r
The quotient is rounded toward negative infinity, as shown in the following table:
a | b | a.divmod(b) | a/b | a.modulo(b) | a.remainder(b) ------+-----+---------------+---------+-------------+--------------- 13 | 4 | 3, 1 | 3 | 1 | 1 ------+-----+---------------+---------+-------------+--------------- 13 | -4 | -4, -3 | -4 | -3 | 1 ------+-----+---------------+---------+-------------+--------------- -13 | 4 | -4, 3 | -4 | 3 | -1 ------+-----+---------------+---------+-------------+--------------- -13 | -4 | 3, -1 | 3 | -1 | -1 ------+-----+---------------+---------+-------------+--------------- 11.5 | 4 | 2, 3.5 | 2.875 | 3.5 | 3.5 ------+-----+---------------+---------+-------------+--------------- 11.5 | -4 | -3, -0.5 | -2.875 | -0.5 | 3.5 ------+-----+---------------+---------+-------------+--------------- -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5 ------+-----+---------------+---------+-------------+--------------- -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
Examples
11.divmod(3) #=> [3, 2] 11.divmod(-3) #=> [-4, -1] 11.divmod(3.5) #=> [3, 0.5] (-11).divmod(3.5) #=> [-4, 3.0] 11.5.divmod(3.5) #=> [3, 1.0]
Changes permission bits on the named file(s) to the bit pattern represented by mode_int. Actual effects are operating system dependent (see the beginning of this section). On Unix systems, see chmod(2)
for details. Returns the number of files processed.
File.chmod(0644, "testfile", "out") #=> 2
Equivalent to File::chmod
, but does not follow symbolic links (so it will change the permissions associated with the link, not the file referenced by the link). Often not available.
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
Creates an infinite enumerator from any block, just called over and over. The result of the previous iteration is passed to the next one. If initial
is provided, it is passed to the first iteration, and becomes the first element of the enumerator; if it is not provided, the first iteration receives nil
, and its result becomes the first element of the iterator.
Raising StopIteration
from the block stops an iteration.
Enumerator.produce(1, &:succ) # => enumerator of 1, 2, 3, 4, .... Enumerator.produce { rand(10) } # => infinite random number sequence ancestors = Enumerator.produce(node) { |prev| node = prev.parent or raise StopIteration } enclosing_section = ancestors.find { |n| n.type == :section }
Using ::produce
together with Enumerable
methods like Enumerable#detect
, Enumerable#slice, Enumerable#take_while
can provide Enumerator-based alternatives for while
and until
cycles:
# Find next Tuesday require "date" Enumerator.produce(Date.today, &:succ).detect(&:tuesday?) # Simple lexer: require "strscan" scanner = StringScanner.new("7+38/6") PATTERN = %r{\d+|[-/+*]} Enumerator.produce { scanner.scan(PATTERN) }.slice_after { scanner.eos? }.first # => ["7", "+", "38", "/", "6"]
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)
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("42") b = BigDecimal("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.
Puts ios into binary mode. Once a stream is in binary mode, it cannot be reset to nonbinary mode.
newline conversion disabled
encoding conversion disabled
content is treated as ASCII-8BIT
Returns true
if ios is binmode.
Turns the database’s fast mode on or off. If fast mode is turned on, gdbm does not wait for writes to be flushed to the disk before continuing.
This option is obsolete for gdbm >= 1.8 since fast mode is turned on by default. See also: syncmode=
Puts stream into binary mode. See IO#binmode
.
Puts ARGF
into binary mode. Once a stream is in binary mode, it cannot be reset to non-binary mode. This option has the following effects:
Newline conversion is disabled.
Encoding
conversion is disabled.
Content is treated as ASCII-8BIT.
Returns true if ARGF
is being read in binary mode; false otherwise. To enable binary mode use ARGF.binmode
.
For example:
ARGF.binmode? #=> false ARGF.binmode ARGF.binmode? #=> true
Returns a BubbleBabble encoded version of a given string.
Changes permission bits on the named files (in list
) to the bit pattern represented by mode
.
mode
is the symbolic and absolute mode can be used.
Absolute mode is
FileUtils.chmod 0755, 'somecommand' FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb) FileUtils.chmod 0755, '/usr/bin/ruby', verbose: true
Symbolic mode is
FileUtils.chmod "u=wrx,go=rx", 'somecommand' FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb) FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', verbose: true
is user, group, other mask.
is user’s mask.
is group’s mask.
is other’s mask.
is write permission.
is read permission.
is execute permission.
is execute permission for directories only, must be used in conjunction with “+”
is uid, gid.
is sticky bit.
is added to a class given the specified mode.
Is removed from a given class given mode.
Is the exact nature of the class will be given a specified mode.