creates a new Socket
connected to the address of local_addrinfo
.
If local_addrinfo is nil, the address of the socket is not bound.
The timeout specify the seconds for timeout. Errno::ETIMEDOUT is raised when timeout occur.
If a block is given the created socket is yielded for each address.
Returns true for IPv4 loopback address (127.0.0.0/8). It returns false otherwise.
Returns true for IPv6 loopback address (::1). It returns false otherwise.
Returns true for IPv6 link local address (fe80::/10). It returns false otherwise.
Returns true for IPv6 site local address (fec0::/10). It returns false otherwise.
Receives up to maxlen bytes from udpsocket
using recvfrom(2) after O_NONBLOCK is set for the underlying file descriptor. flags is zero or more of the MSG_
options. The first element of the results, mesg, is the data received. The second element, sender_inet_addr, is an array to represent the sender address.
When recvfrom(2) returns 0, Socket#recvfrom_nonblock
returns an empty string as data. It means an empty packet.
maxlen
- the number of bytes to receive from the socket
flags
- zero or more of the MSG_
options
outbuf
- destination String
buffer
options
- keyword hash, supporting ‘exception: false`
require 'socket' s1 = UDPSocket.new s1.bind("127.0.0.1", 0) s2 = UDPSocket.new s2.bind("127.0.0.1", 0) s2.connect(*s1.addr.values_at(3,1)) s1.connect(*s2.addr.values_at(3,1)) s1.send "aaa", 0 begin # emulate blocking recvfrom p s2.recvfrom_nonblock(10) #=> ["aaa", ["AF_INET", 33302, "localhost.localdomain", "127.0.0.1"]] rescue IO::WaitReadable IO.select([s2]) retry end
Refer to Socket#recvfrom
for the exceptions that may be thrown if the call to recvfrom_nonblock fails.
UDPSocket#recvfrom_nonblock
may raise any error corresponding to recvfrom(2) failure, including Errno::EWOULDBLOCK.
If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by IO::WaitReadable
. So IO::WaitReadable
can be used to rescue the exceptions for retrying recvfrom_nonblock.
By specifying a keyword argument exception to false
, you can indicate that recvfrom_nonblock
should not raise an IO::WaitReadable
exception, but return the symbol :wait_readable
instead.
Accepts an incoming connection using accept(2) after O_NONBLOCK is set for the underlying file descriptor. It returns an accepted TCPSocket
for the incoming connection.
require 'socket' serv = TCPServer.new(2202) begin # emulate blocking accept sock = serv.accept_nonblock rescue IO::WaitReadable, Errno::EINTR IO.select([serv]) retry end # sock is an accepted socket.
Refer to Socket#accept
for the exceptions that may be thrown if the call to TCPServer#accept_nonblock
fails.
TCPServer#accept_nonblock
may raise any error corresponding to accept(2) failure, including Errno::EWOULDBLOCK.
If the exception is Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, it is extended by IO::WaitReadable
. So IO::WaitReadable
can be used to rescue the exceptions for retrying accept_nonblock.
By specifying a keyword argument exception to false
, you can indicate that accept_nonblock
should not raise an IO::WaitReadable
exception, but return the symbol :wait_readable
instead.
Accepts an incoming connection using accept(2) after O_NONBLOCK is set for the underlying file descriptor. It returns an accepted UNIXSocket
for the incoming connection.
require 'socket' serv = UNIXServer.new("/tmp/sock") begin # emulate blocking accept sock = serv.accept_nonblock rescue IO::WaitReadable, Errno::EINTR IO.select([serv]) retry end # sock is an accepted socket.
Refer to Socket#accept
for the exceptions that may be thrown if the call to UNIXServer#accept_nonblock
fails.
UNIXServer#accept_nonblock
may raise any error corresponding to accept(2) failure, including Errno::EWOULDBLOCK.
If the exception is Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::ECONNABORTED or Errno::EPROTO, it is extended by IO::WaitReadable
. So IO::WaitReadable
can be used to rescue the exceptions for retrying accept_nonblock.
By specifying a keyword argument exception to false
, you can indicate that accept_nonblock
should not raise an IO::WaitReadable
exception, but return the symbol :wait_readable
instead.
Closes self
for reading; closed-write setting remains unchanged.
Raises IOError
if reading is attempted.
Related: StringIO#close
, StringIO#close_write
.
Closes self
for writing; closed-read setting remains unchanged.
Raises IOError
if writing is attempted.
Related: StringIO#close
, StringIO#close_read
.
Returns true
if self
is closed for reading, false
otherwise.
Returns true
if self
is closed for writing, false
otherwise.
Returns the Encoding
object that represents the encoding of the file. If the stream is write mode and no encoding is specified, returns nil
.
Returns the Encoding
of the internal string if conversion is specified. Otherwise returns nil
.
This method is defined for backward compatibility.
Scans one byte and returns it. This method is not multibyte character sensitive. See also: getch
.
s = StringScanner.new('ab') s.get_byte # => "a" s.get_byte # => "b" s.get_byte # => nil s = StringScanner.new("\244\242".force_encoding("euc-jp")) s.get_byte # => "\xA4" s.get_byte # => "\xA2" s.get_byte # => nil
Defines the constants of OLE Automation server as mod’s constants. The first argument is WIN32OLE
object or type library name. If 2nd argument is omitted, the default is WIN32OLE
. The first letter of Ruby’s constant variable name is upper case, so constant variable name of WIN32OLE
object is capitalized. For example, the ‘xlTop’ constant of Excel is changed to ‘XlTop’ in WIN32OLE
. If the first letter of constant variable is not [A-Z], then the constant is defined as CONSTANTS hash element.
module EXCEL_CONST end excel = WIN32OLE.new('Excel.Application') WIN32OLE.const_load(excel, EXCEL_CONST) puts EXCEL_CONST::XlTop # => -4160 puts EXCEL_CONST::CONSTANTS['_xlDialogChartSourceData'] # => 541 WIN32OLE.const_load(excel) puts WIN32OLE::XlTop # => -4160 module MSO end WIN32OLE.const_load('Microsoft Office 9.0 Object Library', MSO) puts MSO::MsoLineSingle # => 1
If obj
is a Hash object, returns obj
.
Otherwise if obj
responds to :to_hash
, calls obj.to_hash
and returns the result.
Returns nil
if obj
does not respond to :to_hash
Raises an exception unless obj.to_hash
returns a Hash object.
Reads at most maxlen bytes from the ARGF
stream in non-blocking mode.
Returns the external encoding for files read from ARGF
as an Encoding
object. The external encoding is the encoding of the text as stored in a file. Contrast with ARGF.internal_encoding
, which is the encoding used to represent this text within Ruby.
To set the external encoding use ARGF.set_encoding
.
For example:
ARGF.external_encoding #=> #<Encoding:UTF-8>
Returns the internal encoding for strings read from ARGF
as an Encoding
object.
If ARGF.set_encoding
has been called with two encoding names, the second is returned. Otherwise, if Encoding.default_external
has been set, that value is returned. Failing that, if a default external encoding was specified on the command-line, that value is used. If the encoding is unknown, nil
is returned.
Returns the value that determines whether unconverted fields are to be available; used for parsing; see {Option unconverted_fields
}:
CSV.new('').unconverted_fields? # => nil
Returns the value that determines whether headers are to be returned; used for parsing; see {Option return_headers
}:
CSV.new('').return_headers? # => false