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 the value raised to the power of n.
Note that n must be an Integer
.
Also available as the operator **.
Returns True if the value is zero.
Returns self if the value is non-zero, nil otherwise.
The coerce method provides support for Ruby type coercion. It is not enabled by default.
This means that binary operations like + * / or - can often be performed on a BigDecimal
and an object of another type, if the other object can be coerced into a BigDecimal
value.
e.g.
a = BigDecimal("1.0") b = a / 2.0 #=> 0.5
Note that coercing a String
to a BigDecimal
is not supported by default; it requires a special compile-time option when building Ruby.
Returns the numerator.
Rational(7).numerator #=> 7 Rational(7, 1).numerator #=> 7 Rational(9, -4).numerator #=> -9 Rational(-2, -10).numerator #=> 1
Returns the largest number less than or equal to rat
with a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns a rational when ndigits
is positive, otherwise returns an integer.
Rational(3).floor #=> 3 Rational(2, 3).floor #=> 0 Rational(-3, 2).floor #=> -2 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 Rational('-123.456').floor(+1).to_f #=> -123.5 Rational('-123.456').floor(-1) #=> -130
Creates a date object denoting the given week date.
The week and the day of week should be a negative or a positive number (as a relative week/day from the end of year/week when negative). They should not be zero.
Date.commercial(2001) #=> #<Date: 2001-01-01 ...> Date.commercial(2002) #=> #<Date: 2001-12-31 ...> Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
Creates a DateTime
object denoting the given week date.
DateTime.commercial(2001) #=> #<DateTime: 2001-01-01T00:00:00+00:00 ...> DateTime.commercial(2002) #=> #<DateTime: 2001-12-31T00:00:00+00:00 ...> DateTime.commercial(2001,5,6,4,5,6,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Same as Time::gm
, but interprets the values in the local time zone.
Time.local(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 -0600
Converts time to local time (using the local time zone in effect at the creation time of time) modifying the receiver.
If utc_offset
is given, it is used instead of the local time.
t = Time.utc(2000, "jan", 1, 20, 15, 1) #=> 2000-01-01 20:15:01 UTC t.utc? #=> true t.localtime #=> 2000-01-01 14:15:01 -0600 t.utc? #=> false t.localtime("+09:00") #=> 2000-01-02 05:15:01 +0900 t.utc? #=> false
If utc_offset
is not given and time is local time, just returns the receiver.
Returns a new Time
object representing time in UTC.
t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600 t.gmt? #=> false y = t.getgm #=> 2000-01-02 02:15:01 UTC y.gmt? #=> true t == y #=> true
Returns a new Time
object representing time in UTC.
t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600 t.gmt? #=> false y = t.getgm #=> 2000-01-02 02:15:01 UTC y.gmt? #=> true t == y #=> true
Floors sub seconds to a given precision in decimal digits (0 digits by default). It returns a new Time
object. ndigits
should be zero or a positive integer.
require 'time' t = Time.utc(2010,3,30, 5,43,25.123456789r) t.iso8601(10) #=> "2010-03-30T05:43:25.1234567890Z" t.floor.iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z" t.floor(0).iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z" t.floor(1).iso8601(10) #=> "2010-03-30T05:43:25.1000000000Z" t.floor(2).iso8601(10) #=> "2010-03-30T05:43:25.1200000000Z" t.floor(3).iso8601(10) #=> "2010-03-30T05:43:25.1230000000Z" t.floor(4).iso8601(10) #=> "2010-03-30T05:43:25.1234000000Z" t = Time.utc(1999,12,31, 23,59,59) (t + 0.4).floor.iso8601(3) #=> "1999-12-31T23:59:59.000Z" (t + 0.9).floor.iso8601(3) #=> "1999-12-31T23:59:59.000Z" (t + 1.4).floor.iso8601(3) #=> "2000-01-01T00:00:00.000Z" (t + 1.9).floor.iso8601(3) #=> "2000-01-01T00:00:00.000Z" t = Time.utc(1999,12,31, 23,59,59) (t + 0.123456789).floor(4).iso8601(6) #=> "1999-12-31T23:59:59.123400Z"
Closes the database.
Returns true if the database is closed, false otherwise.
Returns a Hash
(not a DBM
database) created by using each value in the database as a key, with the corresponding key as its value.
Returns true if the database contains the specified key, false otherwise.
Yields each member value from the struct to the block and returns an Array
containing the member values from the struct
for which the given block returns a true value (equivalent to Enumerable#select
).
Lots = Struct.new(:a, :b, :c, :d, :e, :f) l = Lots.new(11, 22, 33, 44, 55, 66) l.select {|v| v.even? } #=> [22, 44, 66]
Struct#filter
is an alias for Struct#select
.
Returns the struct members as an array of symbols:
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.members #=> [:name, :address, :zip]
Reads and returns a character in raw mode.
See IO#raw
for details on the parameters.
You must require ‘io/console’ to use this method.
Reads and returns a line without echo back. Prints prompt
unless it is nil
.
You must require ‘io/console’ to use this method.
Returns true
if an IO
object is in non-blocking mode.
Enables non-blocking mode on a stream when set to true
, and blocking mode when set to false
.
Yields self
in non-blocking mode.
When false
is given as an argument, self
is yielded in blocking mode. The original mode is restored after the block is executed.