creates a UDP/IP server on port and calls the block for each message arrived. The block is called with the message and its source information.
This method allocates sockets internally using port. If host is specified, it is used conjunction with port to determine the server addresses.
The msg is a string.
The msg_src is a Socket::UDPSource
object. It is used for reply.
# UDP/IP echo server. Socket.udp_server_loop(9261) {|msg, msg_src| msg_src.reply msg }
creates a UNIX socket server on path. It calls the block for each socket accepted.
If host is specified, it is used with port to determine the server ports.
The socket is not closed when the block returns. So application should close it.
This method deletes the socket file pointed by path at first if the file is a socket file and it is owned by the user of the application. This is safe only if the directory of path is not changed by a malicious user. So don’t use /tmp/malicious-users-directory/socket. Note that /tmp/socket and /tmp/your-private-directory/socket is safe assuming that /tmp has sticky bit.
# Sequential echo server. # It services only one client at a time. Socket.unix_server_loop("/tmp/sock") {|sock, client_addrinfo| begin IO.copy_stream(sock, sock) ensure sock.close end }
Generates new parameters for the algorithm. algo_name is a String
that represents the algorithm. The optional argument options is a Hash
that specifies the options specific to the algorithm. The order of the options can be important.
A block can be passed optionally. The meaning of the arguments passed to the block varies depending on the implementation of the algorithm. The block may be called once or multiple times, or may not even be called.
For the supported options, see the documentation for the ‘openssl genpkey’ utility command.
pkey = OpenSSL::PKey.generate_parameters("DSA", "dsa_paramgen_bits" => 2048) p pkey.p.num_bits #=> 2048
Run UDP/IP server loop on the given sockets.
The return value of Socket.udp_server_sockets
is appropriate for the argument.
It calls the block for each message received.
Returns true if the set is a proper superset of the given set.
Returns the String created by generating CSV from ary
using the specified options
.
Argument ary
must be an Array.
Special options:
Option :row_sep
defaults to "\n"> on Ruby 3.0 or later and <tt>$INPUT_RECORD_SEPARATOR
($/
) otherwise.:
$INPUT_RECORD_SEPARATOR # => "\n"
This method accepts an additional option, :encoding
, which sets the base Encoding
for the output. This method will try to guess your Encoding
from the first non-nil
field in row
, if possible, but you may need to use this parameter as a backup plan.
For other options
, see Options for Generating.
Returns the String generated from an Array:
CSV.generate_line(['foo', '0']) # => "foo,0\n"
Raises an exception if ary
is not an Array:
# Raises NoMethodError (undefined method `find' for :foo:Symbol) CSV.generate_line(:foo)
Returns the String created by generating CSV from using the specified options
.
Argument rows
must be an Array of row. Row
is Array of String or CSV::Row.
Special options:
Option :row_sep
defaults to "\n"
on Ruby 3.0 or later and $INPUT_RECORD_SEPARATOR
($/
) otherwise.:
$INPUT_RECORD_SEPARATOR # => "\n"
This method accepts an additional option, :encoding
, which sets the base Encoding
for the output. This method will try to guess your Encoding
from the first non-nil
field in row
, if possible, but you may need to use this parameter as a backup plan.
For other options
, see Options for Generating.
Returns the String generated from an
CSV.generate_lines([['foo', '0'], ['bar', '1'], ['baz', '2']]) # => "foo,0\nbar,1\nbaz,2\n"
Raises an exception
# Raises NoMethodError (undefined method `each' for :foo:Symbol) CSV.generate_lines(:foo)
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
Return the appropriate error message in POSIX-defined format. If no error has occurred, returns nil
.
Returns the current execution stack—an array containing backtrace location objects.
See Thread::Backtrace::Location
for more information.
The optional start parameter determines the number of initial stack entries to omit from the top of the stack.
A second optional length
parameter can be used to limit how many entries are returned from the stack.
Returns nil
if start is greater than the size of current execution stack.
Optionally you can pass a range, which will return an array containing the entries within the specified range.