Returns true
if rat
is less than 0.
Returns the absolute value of rat
.
(1/2r).abs #=> (1/2) (-1/2r).abs #=> (1/2)
Rational#magnitude
is an alias for Rational#abs
.
Returns rat
truncated (toward zero) to 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).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 Rational('-123.456').truncate(+1).to_f #=> -123.4 Rational('-123.456').truncate(-1) #=> -120
Returns a simpler approximation of the value if the optional argument eps
is given (rat-|eps| <= result <= rat+|eps|), self otherwise.
r = Rational(5033165, 16777216) r.rationalize #=> (5033165/16777216) r.rationalize(Rational('0.01')) #=> (3/10) r.rationalize(Rational('0.1')) #=> (1/3)
Returns a hash of parsed elements.
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
Creates a new Date
object by parsing from a string according to some RFC 2616 format.
Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT') #=> #<Date: 2001-02-03 ...>
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
Returns true if the date is Saturday.
This method is equivalent to strftime(‘%a, %d %b %Y %T GMT’). See also RFC 2616.
Creates a new DateTime
object by parsing from a string according to some RFC 2616 format.
DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT') #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
Parses date
as an HTTP-date defined by RFC 2616 and converts it to a Time
object.
ArgumentError
is raised if date
is not compliant with RFC 2616 or if the Time
class cannot represent specified date.
See httpdate
for more information on this format.
require 'time' Time.httpdate("Thu, 06 Oct 2011 02:26:12 GMT") #=> 2011-10-06 02:26:12 UTC
You must require ‘time’ to use this method.
Returns a string which represents the time as RFC 1123 date of HTTP-date defined by RFC 2616:
day-of-week, DD month-name CCYY hh:mm:ss GMT
Note that the result is always UTC (GMT).
require 'time' t = Time.now t.httpdate # => "Thu, 06 Oct 2011 02:26:12 GMT"
You must require ‘time’ to use this method.
Creates a new Time
object with the value given by time
, the given number of seconds_with_frac
, or seconds
and microseconds_with_frac
since the Epoch. seconds_with_frac
and microseconds_with_frac
can be an Integer
, Float
, Rational
, or other Numeric
.
If in
argument is given, the result is in that timezone or UTC offset, or if a numeric argument is given, the result is in local time. The in
argument accepts the same types of arguments as tz
argument of Time.new
: string, number of seconds, or a timezone object.
Time.at(0) #=> 1969-12-31 18:00:00 -0600 Time.at(Time.at(0)) #=> 1969-12-31 18:00:00 -0600 Time.at(946702800) #=> 1999-12-31 23:00:00 -0600 Time.at(-284061600) #=> 1960-12-31 00:00:00 -0600 Time.at(946684800.2).usec #=> 200000 Time.at(946684800, 123456.789).nsec #=> 123456789 Time.at(946684800, 123456789, :nsec).nsec #=> 123456789 Time.at(1582721899, in: "+09:00") #=> 2020-02-26 21:58:19 +0900 Time.at(1582721899, in: "UTC") #=> 2020-02-26 12:58:19 UTC Time.at(1582721899, in: "C") #=> 2020-02-26 13:58:19 +0300 Time.at(1582721899, in: 32400) #=> 2020-02-26 21:58:19 +0900 require 'tzinfo' Time.at(1582721899, in: TZInfo::Timezone.get('Europe/Kiev')) #=> 2020-02-26 14:58:19 +0200
Creates a Time
object based on given values, interpreted as UTC (GMT). The year must be specified. Other values default to the minimum value for that field (and may be nil
or omitted). Months may be specified by numbers from 1 to 12, or by the three-letter English
month names. Hours are specified on a 24-hour clock (0..23). Raises an ArgumentError
if any values are out of range. Will also accept ten arguments in the order output by Time#to_a
.
sec_with_frac
and usec_with_frac
can have a fractional part.
Time.utc(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
Converts time to UTC (GMT), modifying the receiver.
t = Time.now #=> 2007-11-19 08:18:31 -0600 t.gmt? #=> false t.gmtime #=> 2007-11-19 14:18:31 UTC t.gmt? #=> true t = Time.now #=> 2007-11-19 08:18:51 -0600 t.utc? #=> false t.utc #=> 2007-11-19 14:18:51 UTC t.utc? #=> 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
Returns true
if time represents a time in UTC (GMT).
t = Time.now #=> 2007-11-19 08:15:23 -0600 t.utc? #=> false t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC t.utc? #=> true t = Time.now #=> 2007-11-19 08:16:03 -0600 t.gmt? #=> false t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC t.gmt? #=> true
Returns true
if time represents Saturday.
t = Time.local(2006, 6, 10) #=> 2006-06-10 00:00:00 -0500 t.saturday? #=> true
Calls the block once for each [key, value] pair in the database. Returns self.
Updates the database with multiple values from the specified object. Takes any object which implements the each_pair
method, including Hash
and DBM
objects.
Yields the value of each struct member in order. If no block is given an enumerator is returned.
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.each {|x| puts(x) }
Produces:
Joe Smith 123 Maple, Anytown NC 12345
Returns pathname configuration variable using fpathconf().
name should be a constant under Etc
which begins with PC_
.
The return value is an integer or nil. nil means indefinite limit. (fpathconf() returns -1 but errno is not set.)
require 'etc' IO.pipe {|r, w| p w.pathconf(Etc::PC_PIPE_BUF) #=> 4096 }
Enables/disables echo back. On some platforms, all combinations of this flags and raw/cooked mode may not be valid.
You must require ‘io/console’ to use this method.
Yields self
with disabling echo back.
STDIN.noecho(&:gets)
will read and return a line without echo back.
You must require ‘io/console’ to use this method.
Returns status information for ios as an object of type File::Stat
.
f = File.new("testfile") s = f.stat "%o" % s.mode #=> "100644" s.blksize #=> 4096 s.atime #=> Wed Apr 09 08:53:54 CDT 2003