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 ...>
See also jd and new.
Returns a hash of parsed elements.
Creates a new Date
object by parsing from a string according to some typical XML
Schema formats.
Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
Returns the value as a string for inspection.
Date.new(2001,2,3).inspect #=> "#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>" DateTime.new(2001,2,3,4,5,6,'-7').inspect #=> "#<DateTime: 2001-02-03T04:05:06-07:00 ((2451944j,39906s,0n),-25200s,2299161j)>"
This method is equivalent to strftime(‘%F’).
Creates a date-time 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 ...>
Creates a new Date
object by parsing from a string according to some typical XML
Schema formats.
DateTime.xmlschema('2001-02-03T04:05:06+07:00') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
This method is equivalent to strftime(‘%FT%T%:z’). The optional argument n
is the number of digits for fractional seconds.
DateTime.parse('2001-02-03T04:05:06.123456789+07:00').iso8601(9) #=> "2001-02-03T04:05:06.123456789+07:00"
Parses date
as a dateTime defined by the XML
Schema and converts it to a Time
object. The format is a restricted version of the format defined by ISO 8601.
ArgumentError
is raised if date
is not compliant with the format or if the Time
class cannot represent specified date.
See xmlschema
for more information on this format.
You must require ‘time’ to use this method.
Returns a string which represents the time as a dateTime defined by XML
Schema:
CCYY-MM-DDThh:mm:ssTZD CCYY-MM-DDThh:mm:ss.sssTZD
where TZD is Z or [+-]hh:mm.
If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
fractional_digits
specifies a number of digits to use for fractional seconds. Its default value is 0.
You must require ‘time’ to use this method.
Returns a string representing time. Equivalent to calling strftime
with the appropriate format string.
t = Time.now t.to_s => "2012-11-10 18:16:12 +0100" t.strftime "%Y-%m-%d %H:%M:%S %z" => "2012-11-10 18:16:12 +0100" t.utc.to_s => "2012-11-10 17:16:12 UTC" t.strftime "%Y-%m-%d %H:%M:%S UTC" => "2012-11-10 17:16:12 UTC"
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.
Describe the contents of this struct in a string.
Tries to set console size. The effect depends on the platform and the running environment.
You must require ‘io/console’ to use this method.
Reads the entire file specified by name as individual lines, and returns those lines in an array. Lines are separated by sep.
a = IO.readlines("testfile") a[0] #=> "This is line one\n"
If the last argument is a hash, it’s the keyword argument to open. See IO.read
for detail.
Opens the file, optionally seeks to the given offset, then returns length bytes (defaulting to the rest of the file). binread
ensures the file is closed before returning. The open mode would be “rb:ASCII-8BIT”.
IO.binread("testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n" IO.binread("testfile", 20) #=> "This is line one\nThi" IO.binread("testfile", 20, 10) #=> "ne one\nThis is line "
Same as IO.write
except opening the file in binary mode and ASCII-8BIT encoding (“wb:ASCII-8BIT”).
Writes the given object(s) to ios. Returns nil
.
The stream must be opened for writing. Each given object that isn’t a string will be converted by calling its to_s
method. When called without arguments, prints the contents of $_
.
If the output field separator ($,
) is not nil
, it is inserted between objects. If the output record separator ($\
) is not nil
, it is appended to the output.
$stdout.print("This is ", 100, " percent.\n")
produces:
This is 100 percent.
Formats and writes to ios, converting parameters under control of the format string. See Kernel#sprintf
for details.
This is a deprecated alias for each_line
.
This is a deprecated alias for each_codepoint
.
Returns the current line number in ios. The stream must be opened for reading. lineno
counts the number of times gets
is called rather than the number of newlines encountered. The two values will differ if gets
is called with a separator other than newline.
Methods that use $/
like each
, lines
and readline
will also increment lineno
.
See also the $.
variable.
f = File.new("testfile") f.lineno #=> 0 f.gets #=> "This is line one\n" f.lineno #=> 1 f.gets #=> "This is line two\n" f.lineno #=> 2
Manually sets the current line number to the given value. $.
is updated only on the next read.
f = File.new("testfile") f.gets #=> "This is line one\n" $. #=> 1 f.lineno = 1000 f.lineno #=> 1000 $. #=> 1 # lineno of last read f.gets #=> "This is line two\n" $. #=> 1001 # lineno of last read