Returns nil, -1, or +1 depending on whether the value is finite, -Infinity, or +Infinity.
Returns True if the value is finite (not NaN or infinite).
Truncate to the nearest integer (by default), returning the result as a BigDecimal
.
BigDecimal('3.14159').truncate #=> 3 BigDecimal('8.7').truncate #=> 8 BigDecimal('-9.9').truncate #=> -9
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').truncate(3) #=> 3.141 BigDecimal('13345.234').truncate(-2) #=> 13300.0
Returns the absolute value of rat
.
(1/2r).abs #=> 1/2r (-1/2r).abs #=> 1/2r
Rational#magnitude
is an alias of Rational#abs
.
Returns the truncated value (toward zero).
Rational(3).truncate #=> 3 Rational(2, 3).truncate #=> 0 Rational(-3, 2).truncate #=> -1 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 '%f' % Rational('-123.456').truncate(+1) #=> "-123.400000" '%f' % Rational('-123.456').truncate(-1) #=> "-120.000000"
Returns the truncated value (toward the nearest integer; 0.5 => 1; -0.5 => -1).
Rational(3).round #=> 3 Rational(2, 3).round #=> 1 Rational(-3, 2).round #=> -2 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 '%f' % Rational('-123.456').round(+1) #=> "-123.500000" '%f' % Rational('-123.456').round(-1) #=> "-120.000000"
Returns true if the date is Sunday.
Rounds sub seconds to a given precision in decimal digits (0 digits by default). It returns a new Time
object. ndigits
should be zero or positive integer.
require 'time' t = Time.utc(2010,3,30, 5,43,"25.123456789".to_r) p t.iso8601(10) #=> "2010-03-30T05:43:25.1234567890Z" p t.round.iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z" p t.round(0).iso8601(10) #=> "2010-03-30T05:43:25.0000000000Z" p t.round(1).iso8601(10) #=> "2010-03-30T05:43:25.1000000000Z" p t.round(2).iso8601(10) #=> "2010-03-30T05:43:25.1200000000Z" p t.round(3).iso8601(10) #=> "2010-03-30T05:43:25.1230000000Z" p t.round(4).iso8601(10) #=> "2010-03-30T05:43:25.1235000000Z" p t.round(5).iso8601(10) #=> "2010-03-30T05:43:25.1234600000Z" p t.round(6).iso8601(10) #=> "2010-03-30T05:43:25.1234570000Z" p t.round(7).iso8601(10) #=> "2010-03-30T05:43:25.1234568000Z" p t.round(8).iso8601(10) #=> "2010-03-30T05:43:25.1234567900Z" p t.round(9).iso8601(10) #=> "2010-03-30T05:43:25.1234567890Z" p t.round(10).iso8601(10) #=> "2010-03-30T05:43:25.1234567890Z" t = Time.utc(1999,12,31, 23,59,59) p((t + 0.4).round.iso8601(3)) #=> "1999-12-31T23:59:59.000Z" p((t + 0.49).round.iso8601(3)) #=> "1999-12-31T23:59:59.000Z" p((t + 0.5).round.iso8601(3)) #=> "2000-01-01T00:00:00.000Z" p((t + 1.4).round.iso8601(3)) #=> "2000-01-01T00:00:00.000Z" p((t + 1.49).round.iso8601(3)) #=> "2000-01-01T00:00:00.000Z" p((t + 1.5).round.iso8601(3)) #=> "2000-01-01T00:00:01.000Z" t = Time.utc(1999,12,31, 23,59,59) p (t + 0.123456789).round(4).iso8601(6) #=> "1999-12-31T23:59:59.123500Z"
Returns true
if time represents Sunday.
t = Time.local(1990, 4, 1) #=> 1990-04-01 00:00:00 -0600 t.sunday? #=> true
Pushes back bytes (passed as a parameter) onto ios, such that a subsequent buffered read will return it. Only one byte may be pushed back before a subsequent read operation (that is, you will be able to read only the last of several bytes that have been pushed back). Has no effect with unbuffered reads (such as IO#sysread
).
f = File.new("testfile") #=> #<File:testfile> b = f.getbyte #=> 0x38 f.ungetbyte(b) #=> nil f.getbyte #=> 0x38
Pushes back one character (passed as a parameter) onto ios, such that a subsequent buffered character read will return it. Only one character may be pushed back before a subsequent read operation (that is, you will be able to read only the last of several characters that have been pushed back). Has no effect with unbuffered reads (such as IO#sysread
).
f = File.new("testfile") #=> #<File:testfile> c = f.getc #=> "8" f.ungetc(c) #=> nil f.getc #=> "8"
Reorganizes the database file. This operation removes reserved space of elements that have already been deleted. It is only useful after a lot of deletions in the database.
Returns true
if self
points to a mountpoint.
Removes a file or directory, using File.unlink
if self
is a file, or Dir.unlink
as necessary.
This method is called when strong warning is produced by the parser. fmt
and args
is printf style.
Tokenizes the Ruby program and returns an array of strings.
p Ripper.tokenize("def m(a) nil end") # => ["def", " ", "m", "(", "a", ")", " ", "nil", " ", "end"]
Pushes back one character (passed as a parameter) onto strio such that a subsequent buffered read will return it. There is no limitation for multiple pushbacks including pushing back behind the beginning of the buffer string.
Truncates the buffer string to at most integer bytes. The strio must be opened for writing.
Set
the scan pointer to the previous position. Only one previous position is remembered, and it changes with each scanning operation.
s = StringScanner.new('test string') s.scan(/\w+/) # => "test" s.unscan s.scan(/../) # => "te" s.scan(/\d/) # => nil s.unscan # ScanError: unscan failed: previous match record not exist
disconnects OLE server. If this method called, then the WIN32OLE_EVENT
object does not receive the OLE server event any more. This method is trial implementation.
ie = WIN32OLE.new('InternetExplorer.Application') ev = WIN32OLE_EVENT.new(ie) ev.on_event() {...} ... ev.unadvise
Untrust both the object returned by _getobj_ and self.
Untaint both the object returned by _getobj_ and self.