Prints obj on the given port (default $>
). Equivalent to:
def display(port=$>) port.write self nil end
For example:
1.display "cat".display [ 4, 5, 6 ].display puts
produces:
1cat[4, 5, 6]
Performs integer division: returns the integer result of dividing int
by numeric
.
Returns the floating point result of dividing int
by numeric
.
654321.fdiv(13731) #=> 47.652829364212366 654321.fdiv(13731.24) #=> 47.65199646936475 -654321.fdiv(13731) #=> -47.652829364212366
Returns the digits of int
‘s place-value representation with radix base
(default: 10). The digits are returned as an array with the least significant digit as the first array element.
base
must be greater than or equal to 2.
12345.digits #=> [5, 4, 3, 2, 1] 12345.digits(7) #=> [4, 6, 6, 0, 5] 12345.digits(100) #=> [45, 23, 1] -12345.digits(7) #=> Math::DomainError
Performs division as each part is a float, never returns a float.
Complex(11, 22).fdiv(3) #=> (3.6666666666666665+7.333333333333333i)
Returns float division.
Uses /
to perform division, then converts the result to an integer. Numeric
does not define the /
operator; this is left to subclasses.
Equivalent to num.divmod(numeric)[0]
.
See Numeric#divmod
.
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]
Returns the Encoding
object that represents the encoding of obj.
Returns float / numeric
, same as Float#/
.
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
.
Divide by the specified value.
If specified and less than the number of significant digits of the result, the result is rounded to that number of digits, according to BigDecimal.mode
.
If digits is 0, the result is the same as for the / operator or quo
.
If digits is not specified, the result is an integer, by analogy with Float#div
; see also BigDecimal#divmod
.
Examples:
a = BigDecimal("4") b = BigDecimal("3") a.div(b, 3) # => 0.133e1 a.div(b, 0) # => 0.1333333333333333333e1 a / b # => 0.1333333333333333333e1 a.quo(b) # => 0.1333333333333333333e1 a.div(b) # => 1
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.
Performs division and returns the value as a Float
.
Rational(2, 3).fdiv(1) #=> 0.6666666666666666 Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333 Rational(2).fdiv(3) #=> 0.6666666666666666
Synonym for $stdin.
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 ...>
Creates a DateTime
object denoting the given ordinal date.
DateTime.ordinal(2001,34) #=> #<DateTime: 2001-02-03T00:00:00+00:00 ...> DateTime.ordinal(2001,34,4,5,6,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...> DateTime.ordinal(2001,-332,-20,-55,-54,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Finds and returns the object in nested objects that is specified by key
and identifiers
. The nested objects may be instances of various classes. See Dig Methods.
Examples:
Foo = Struct.new(:a) f = Foo.new(Foo.new({b: [1, 2, 3]})) f.dig(:a) # => #<struct Foo a={:b=>[1, 2, 3]}> f.dig(:a, :a) # => {:b=>[1, 2, 3]} f.dig(:a, :a, :b) # => [1, 2, 3] f.dig(:a, :a, :b, 0) # => 1 f.dig(:b, 0) # => nil
Finds and returns the object in nested objects that is specified by name
and identifiers
. The nested objects may be instances of various classes. See Dig Methods.
Examples:
require "ostruct" address = OpenStruct.new("city" => "Anytown NC", "zip" => 12345) person = OpenStruct.new("name" => "John Smith", "address" => address) person.dig(:address, "zip") # => 12345 person.dig(:business_address, "zip") # => nil
Returns the first object in the range, or an array of the first n
elements.
(10..20).first #=> 10 (10..20).first(3) #=> [10, 11, 12]
Returns the Encoding
object that represents the encoding of obj.
Returns true if the set and the given set have no element in common. This method is the opposite of intersect?
.
Set[1, 2, 3].disjoint? Set[3, 4] #=> false Set[1, 2, 3].disjoint? Set[4, 5] #=> true