Results for: "module_function"

recvmsg receives a message using recvmsg(2) system call in non-blocking manner.

It is similar to BasicSocket#recvmsg but non-blocking flag is set before the system call and it doesn’t retry the system call.

By specifying a keyword argument exception to false, you can indicate that recvmsg_nonblock should not raise an IO::WaitReadable exception, but return the symbol :wait_readable instead.

returns a string which shows the sockaddr in addrinfo with human-readable form.

Addrinfo.tcp("localhost", 80).inspect_sockaddr     #=> "127.0.0.1:80"
Addrinfo.tcp("ip6-localhost", 80).inspect_sockaddr #=> "[::1]:80"
Addrinfo.unix("/tmp/sock").inspect_sockaddr        #=> "/tmp/sock"

Returns the IP address and port number as 2-element array.

Addrinfo.tcp("127.0.0.1", 80).ip_unpack    #=> ["127.0.0.1", 80]
Addrinfo.tcp("::1", 80).ip_unpack          #=> ["::1", 80]

Returns true for IPv6 unspecified address (::). It returns false otherwise.

Returns the socket path as a string.

Addrinfo.unix("/tmp/sock").unix_path       #=> "/tmp/sock"

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#recv_nonblock returns nil. In most cases it means the connection was closed, but it may also mean an empty packet was received, as the underlying API makes it impossible to distinguish these two cases.

Parameters

Example

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.

See

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.

Example

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.

See

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.

Example

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.

See

Sends io as file descriptor passing.

s1, s2 = UNIXSocket.pair

s1.send_io STDOUT
stdout = s2.recv_io

p STDOUT.fileno #=> 1
p stdout.fileno #=> 6

stdout.puts "hello" # outputs "hello\n" to standard output.

io may be any kind of IO object or integer file descriptor.

Example

UNIXServer.open("/tmp/sock") {|serv|
  UNIXSocket.open("/tmp/sock") {|c|
    s = serv.accept

    c.send_io STDOUT
    stdout = s.recv_io

    p STDOUT.fileno #=> 1
    p stdout.fileno #=> 7

    stdout.puts "hello" # outputs "hello\n" to standard output.
  }
}

klass will determine the class of io returned (using the IO.for_fd singleton method or similar). If klass is nil, an integer file descriptor is returned.

mode is the same as the argument passed to IO.for_fd

Duplicates a StringScanner object.

Whether scanner uses fixed anchor mode or not.

If fixed anchor mode is used, \A always matches the beginning of the string. Otherwise, \A always matches the current position.

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

Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj). In order to set the context, the variable self is set to obj while the code is executing, giving the code access to obj’s instance variables and private methods.

When instance_eval is given a block, obj is also passed in as the block’s only argument.

When instance_eval is given a String, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.

class KlassWithSecret
  def initialize
    @secret = 99
  end
  private
  def the_secret
    "Ssssh! The secret is #{@secret}."
  end
end
k = KlassWithSecret.new
k.instance_eval { @secret }          #=> 99
k.instance_eval { the_secret }       #=> "Ssssh! The secret is 99."
k.instance_eval {|obj| obj == self } #=> true

Executes the given block within the context of the receiver (obj). In order to set the context, the variable self is set to obj while the code is executing, giving the code access to obj’s instance variables. Arguments are passed as block parameters.

class KlassWithSecret
  def initialize
    @secret = 99
  end
end
k = KlassWithSecret.new
k.instance_exec(5) {|x| @secret+x }   #=> 104

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.

Replaces the entire contents of self with the contents of other_hash; returns self:

h = {foo: 0, bar: 1, baz: 2}
h.replace({bat: 3, bam: 4}) # => {:bat=>3, :bam=>4}

Returns an IO object representing the current file. This will be a File object unless the current file is a stream such as STDIN.

For example:

ARGF.to_io    #=> #<File:glark.txt>
ARGF.to_io    #=> #<IO:<STDIN>>

Reads at most maxlen bytes from the ARGF stream in non-blocking mode.

Returns an Array containing header converters; used for parsing; see Header Converters:

CSV.new('').header_converters # => []

Notes that you need to call +Ractor.make_shareable(CSV::HeaderConverters)+ on the main Ractor to use this method.

No documentation available

The block need not return a String object:

csv = CSV.open(path, headers: true)
csv.header_convert {|header, field_info| header.to_sym }
table = csv.read
table.headers # => [:Name, :Value]

If converter_name is given, the block is not called:

csv = CSV.open(path, headers: true)
csv.header_convert(:downcase) {|header, field_info| fail 'Cannot happen' }
table = csv.read
table.headers # => ["name", "value"]

Raises a parse-time exception if converter_name is not the name of a built-in field converter:

csv = CSV.open(path, headers: true)
csv.header_convert(:nosuch)
# Raises NoMethodError (undefined method `arity' for nil:NilClass)
csv.read
No documentation available

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.

Returns the IPv6 zone identifier, if present. Raises InvalidAddressError if not an IPv6 address.

Search took: 8ms  ·  Total Results: 4789