Invokes Module.prepend_features
on each parameter in reverse order.
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
.
Registers filename to be loaded (using Kernel::require
) the first time that module (which may be a String
or a symbol) is accessed in the namespace of mod.
module A end A.autoload(:B, "b") A::B.doit # autoloads "b"
Returns filename to be loaded if name is registered as autoload
in the namespace of mod.
module A end A.autoload(:B, "b") A.autoload?(:B) #=> "b"
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"
Returns a string representing this module or class. For basic classes and modules, this is the name. For singletons, we show information on the thing we’re attached to as well.
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?
.
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]
Converts the value to a string.
The default format looks like 0.xxxxEnn.
The optional parameter s consists of either an integer; or an optional ‘+’ or ‘ ’, followed by an optional number, followed by an optional ‘E’ or ‘F’.
If there is a ‘+’ at the start of s, positive values are returned with a leading ‘+’.
A space at the start of s returns positive values with a leading space.
If s contains a number, a space is inserted after each group of that many fractional digits.
If s ends with an ‘E’, engineering notation (0.xxxxEnn) is used.
If s ends with an ‘F’, conventional floating point notation is used.
Examples:
BigDecimal.new('-123.45678901234567890').to_s('5F') #=> '-123.45678 90123 45678 9' BigDecimal.new('123.45678901234567890').to_s('+8F') #=> '+123.45678901 23456789' BigDecimal.new('123.45678901234567890').to_s(' F') #=> ' 123.4567890123456789'
Returns the value as an Integer
.
If the BigDecimal
is infinity or NaN, raises FloatDomainError
.
Converts a BigDecimal
to a Rational
.
Returns the remainder from dividing by the value.
x.remainder(y) means x-y*(x/y).truncate
Returns a new Float
object having approximately the same value as the BigDecimal
number. Normal accuracy limits and built-in errors of binary Float
arithmetic apply.
Return the largest integer less than or equal to the value, as a BigDecimal
.
BigDecimal('3.14159').floor #=> 3 BigDecimal('-9.1').floor #=> -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').floor(3) #=> 3.141 BigDecimal('13345.234').floor(-2) #=> 13300.0
Returns self.
require 'bigdecimal/util' d = BigDecimal.new("3.14") d.to_d # => 0.314e1
Returns the value as a BigDecimal
.
The required precision
parameter is used to determine the number of significant digits for the result.
require 'bigdecimal' require 'bigdecimal/util' Rational(22, 7).to_d(3) # => 0.314e1
See also BigDecimal::new
.
Returns the truncated value (toward negative infinity).
Rational(3).floor #=> 3 Rational(2, 3).floor #=> 0 Rational(-3, 2).floor #=> -1 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 '%f' % Rational('-123.456').floor(+1) #=> "-123.500000" '%f' % Rational('-123.456').floor(-1) #=> "-130.000000"
Returns the truncated value as an integer.
Equivalent to Rational#truncate
.
Rational(2, 3).to_i #=> 0 Rational(3).to_i #=> 3 Rational(300.6).to_i #=> 300 Rational(98,71).to_i #=> 1 Rational(-30,2).to_i #=> -15
Return the value as a float.
Rational(2).to_f #=> 2.0 Rational(9, 4).to_f #=> 2.25 Rational(-3, 4).to_f #=> -0.75 Rational(20, 3).to_f #=> 6.666666666666667
Returns the value as a string.
Rational(2).to_s #=> "2/1" Rational(-8, 6).to_s #=> "-4/3" Rational('1/2').to_s #=> "1/2"
Creates a date object denoting the given ordinal date.
The day of year should be a negative or a positive number (as a relative day from the end of year when negative). It should not be zero.
Date.ordinal(2001) #=> #<Date: 2001-01-01 ...> Date.ordinal(2001,34) #=> #<Date: 2001-02-03 ...> Date.ordinal(2001,-1) #=> #<Date: 2001-12-31 ...>