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 ...>
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.
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).
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
. non-portable feature allows the offset to be negative on some systems.
If a numeric argument is given, the result is in local time.
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
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
Executes the block for every line in the named I/O port, where lines are separated by sep.
If no block is given, an enumerator is returned instead.
IO.foreach("testfile") {|x| print "GOT ", x }
produces:
GOT This is line one GOT This is line two GOT This is line three GOT And so on...
If the last argument is a hash, it’s the keyword argument to open. See IO.read
for detail.
If obj is Numeric
, write the character whose code is the least-significant byte of obj, otherwise write the first byte of the string representation of obj to ios. Note: This method is not safe for use with multi-byte characters as it will truncate them.
$stdout.putc "A" $stdout.putc 65
produces:
AA
Executes the block for every line in ios, where lines are separated by sep. ios must be opened for reading or an IOError
will be raised.
If no block is given, an enumerator is returned instead.
f = File.new("testfile") f.each {|line| puts "#{f.lineno}: #{line}" }
produces:
1: This is line one 2: This is line two 3: This is line three 4: And so on...
This is a deprecated alias for each_char
.
Immediately writes all buffered data in ios to disk.
If the underlying operating system does not support fdatasync(2), IO#fsync
is called instead (which might raise a NotImplementedError
).
Reads a one-character string from ios. Returns nil
if called at end of file.
f = File.new("testfile") f.getc #=> "h" f.getc #=> "e"
Reads a one-character string from ios. Raises an EOFError
on end of file.
f = File.new("testfile") f.readchar #=> "h" f.readchar #=> "e"
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"