Returns a string in an ISO 8601 format. (This method doesn’t use the expanded representations.)
DateTime.new(2001,2,3,4,5,6,'-7').to_s #=> "2001-02-03T04:05:06-07:00"
Returns the value of time as an integer number of seconds since the Epoch.
t = Time.now "%10.5f" % t.to_f #=> "1270968656.89607" t.to_i #=> 1270968656
Returns the value of time as a floating point number of seconds since the Epoch.
t = Time.now "%10.5f" % t.to_f #=> "1270968744.77658" t.to_i #=> 1270968744
Note that IEEE 754 double is not accurate enough to represent the number of nanoseconds since the Epoch.
Returns the value of time as a rational number of seconds since the Epoch.
t = Time.now p t.to_r #=> (1270968792716287611/1000000000)
This methods is intended to be used to get an accurate value representing the nanoseconds since the Epoch. You can use this method to convert time to another Epoch.
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 ten-element array of values for time:
[sec, min, hour, day, month, year, wday, yday, isdst, zone]
See the individual methods for an explanation of the valid ranges of each value. The ten elements can be passed directly to Time::utc
or Time::local
to create a new Time
object.
t = Time.now #=> 2007-11-19 08:36:01 -0600 now = t.to_a #=> [1, 36, 8, 19, 11, 2007, 1, 323, false, "CST"]
Converts the contents of the database to an array of [key, value] arrays, and returns it.
Returns the values for this struct as an Array.
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.to_a[1] #=> "123 Maple, Anytown NC"
Returns a Hash
containing the names and values for the struct’s members.
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.to_h[:address] #=> "123 Maple, Anytown NC"
Returns a description of this struct as a string.
Returns an integer representing the numeric file descriptor for ios.
$stdin.fileno #=> 0 $stdout.fileno #=> 1
Returns an array of all key-value pairs contained in the database.
Converts the OpenStruct
to a hash with keys representing each attribute (as symbols) and their corresponding values.
require "ostruct" data = OpenStruct.new("country" => "Australia", :capital => "Canberra") data.to_h # => {:country => "Australia", :capital => "Canberra" }
Convert this range object to a printable form (using to_s
to convert the begin and end objects).
Returns a string containing the regular expression and its options (using the (?opts:source)
notation. This string can be fed back in to Regexp::new
to a regular expression with the same semantics as the original. (However, Regexp#==
may not return true when comparing the two, as the source of the regular expression itself may differ, as the example shows). Regexp#inspect
produces a generally more readable version of rxp.
r1 = /ab+c/ix #=> /ab+c/ix s1 = r1.to_s #=> "(?ix-m:ab+c)" r2 = Regexp.new(s1) #=> /(?ix-m:ab+c)/ r1 == r2 #=> false r1.source #=> "ab+c" r2.source #=> "(?ix-m:ab+c)"
Returns the name or string corresponding to sym.
:fred.id2name #=> "fred" :ginger.to_s #=> "ginger"
Return the path as a String.
to_path
is implemented so Pathname
objects are usable with File.open
, etc.
Returns a new Array containing each key-value pair in the database.
Example:
require 'sdbm' SDBM.open 'my_database' do |db| db.update('apple' => 'fruit', 'spinach' => 'vegetable') db.to_a #=> [["apple", "fruit"], ["spinach", "vegetable"]] end
returns the socket address as packed struct sockaddr string.
Addrinfo.tcp("localhost", 80).to_sockaddr #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
Converts hsh to a nested array of [
key, value ]
arrays.
h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 } h.to_a #=> [["c", 300], ["a", 100], ["d", 400]]
Return the contents of this hash as a string.
h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 } h.to_s #=> "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
Converts the environment variables into an array of names and value arrays.
ENV.to_a # => [["TERM", "xterm-color"], ["SHELL", "/bin/bash"], ...]
Returns “ENV”