Try to convert obj into a Regexp
, using to_regexp method. Returns converted regexp or nil if obj cannot be converted for any reason.
Regexp.try_convert(/re/) #=> /re/ Regexp.try_convert("re") #=> nil o = Object.new Regexp.try_convert(o) #=> nil def o.to_regexp() /foo/ end Regexp.try_convert(o) #=> /foo/
Requests a connection to be made on the given remote_sockaddr
after O_NONBLOCK is set for the underlying file descriptor. Returns 0 if successful, otherwise an exception is raised.
# +remote_sockaddr+ - the +struct+ sockaddr contained in a string or Addrinfo object
# Pull down Google's web page require 'socket' include Socket::Constants socket = Socket.new(AF_INET, SOCK_STREAM, 0) sockaddr = Socket.sockaddr_in(80, 'www.google.com') begin # emulate blocking connect socket.connect_nonblock(sockaddr) rescue IO::WaitWritable IO.select(nil, [socket]) # wait 3-way handshake completion begin socket.connect_nonblock(sockaddr) # check connection failure rescue Errno::EISCONN end end socket.write("GET / HTTP/1.0\r\n\r\n") results = socket.read
Refer to Socket#connect
for the exceptions that may be thrown if the call to connect_nonblock fails.
Socket#connect_nonblock
may raise any error corresponding to connect(2) failure, including Errno::EINPROGRESS.
If the exception is Errno::EINPROGRESS, it is extended by IO::WaitWritable
. So IO::WaitWritable
can be used to rescue the exceptions for retrying connect_nonblock.
By specifying a keyword argument exception to false
, you can indicate that connect_nonblock
should not raise an IO::WaitWritable
exception, but return the symbol :wait_writable
instead.
# Socket#connect
Returns true for IPv4 multicast address (224.0.0.0/4). It returns false otherwise.
Returns true for IPv6 multicast address (ff00::/8). It returns false otherwise.
This method is defined for backward compatibility.
Scans the string until the pattern
is matched. Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, nil
is returned.
s = StringScanner.new("Fri Dec 12 1975 14:39") s.scan_until(/1/) # -> "Fri Dec 1" s.pre_match # -> "Fri Dec " s.scan_until(/XYZ/) # -> nil
Advances the scan pointer until pattern
is matched and consumed. Returns the number of bytes advanced, or nil
if no match was found.
Look ahead to match pattern
, and advance the scan pointer to the end of the match. Return the number of characters advanced, or nil
if the match was unsuccessful.
It’s similar to scan_until
, but without returning the intervening string.
s = StringScanner.new("Fri Dec 12 1975 14:39") s.skip_until /12/ # -> 10 s #
This returns the value that scan_until
would return, without advancing the scan pointer. The match register is affected, though.
s = StringScanner.new("Fri Dec 12 1975 14:39") s.check_until /12/ # -> "Fri Dec 12" s.pos # -> 0 s.matched # -> 12
Mnemonic: it “checks” to see whether a scan_until
will return a value.
Returns the size of arguments of the method.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbook') method = WIN32OLE_METHOD.new(tobj, 'SaveAs') puts method.size_params # => 11
Returns major version.
tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents') puts tobj.major_version # => 8
Returns minor version.
tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents') puts tobj.minor_version # => 2
Returns the type library major version.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.major_version # -> 1
Returns the type library minor version.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.minor_version # -> 3
Try to convert obj into a hash, using to_hash
method. Returns converted hash or nil if obj cannot be converted for any reason.
Hash.try_convert({1=>2}) # => {1=>2} Hash.try_convert("1=>2") # => nil
This method is a shortcut for converting a single line of a CSV
String into an Array. Note that if line
contains multiple rows, anything beyond the first row is ignored.
The options
parameter can be anything CSV::new()
understands.
Returns true
if unconverted_fields() to parsed results. See CSV::new
for details.
Returns the current list of converters in effect for headers. See CSV::new
for details. Built-in converters will be returned by name, while others will be returned as is.
Returns true
if illegal input is handled. See CSV::new
for details.
Identical to CSV#convert()
, but for header rows.
Note that this method must be called before header rows are read to have any effect.
The actual work method for adding converters, used by both CSV.convert()
and CSV.header_convert()
.
This method requires the var_name
of the instance variable to place the converters in, the const
Hash
to lookup named converters in, and the normal parameters of the CSV.convert()
and CSV.header_convert()
methods.
Processes fields
with @converters
, or @header_converters
if headers
is passed as true
, returning the converted field set. Any converter that changes the field into something other than a String halts the pipeline of conversion for that field. This is primarily an efficiency shortcut.
This method is used to turn a finished row
into a CSV::Row
. Header rows are also dealt with here, either by returning a CSV::Row
with identical headers and fields (save that the fields do not go through the converters) or by reading past them to return a field row. Headers are also saved in @headers
for use in future rows.
When nil
, row
is assumed to be a header row not based on an actual row of the stream.
Returns a string for DNS reverse lookup compatible with RFC3172.
Set
date-time format.
datetime_format
A string suitable for passing to strftime
.