Creates a new UDPSocket
object.
address_family should be an integer, a string or a symbol: Socket::AF_INET, “AF_INET”, :INET, etc.
require 'socket' UDPSocket.new #=> #<UDPSocket:fd 3> UDPSocket.new(Socket::AF_INET6) #=> #<UDPSocket:fd 4>
Creates a new server socket bound to port.
If hostname is given, the socket is bound to it.
serv = TCPServer.new("127.0.0.1", 28561) s = serv.accept s.puts Time.now s.close
Internally, TCPServer.new
calls getaddrinfo() function to obtain addresses. If getaddrinfo() returns multiple addresses, TCPServer.new
tries to create a server socket for each address and returns first one that is successful.
Creates a new UNIX server socket bound to path.
require 'socket' serv = UNIXServer.new("/tmp/sock") s = serv.accept p s.read
Opens a SOCKS connection to host
via the SOCKS server serv
.
Opens a TCP connection to remote_host
on remote_port
. If local_host
and local_port
are specified, then those parameters are used on the local end to establish the connection.
Creates a new UNIX client socket connected to path.
require 'socket' s = UNIXSocket.new("/tmp/sock") s.send "hello", 0
Creates new StringIO
instance from with string and mode.
Creates a new StringScanner
object to scan over the given string
. dup
argument is obsolete and not used now.
Returns a new WIN32OLE
object(OLE Automation object). The first argument server specifies OLE Automation server. The first argument should be CLSID or PROGID. If second argument host specified, then returns OLE Automation object on host. If :license keyword argument is provided, IClassFactory2::CreateInstanceLic is used to create instance of licensed server.
WIN32OLE.new('Excel.Application') # => Excel OLE Automation WIN32OLE object. WIN32OLE.new('{00024500-0000-0000-C000-000000000046}') # => Excel OLE Automation WIN32OLE object.
Not documented
Returns a new, empty hash. If this hash is subsequently accessed by a key that doesn’t correspond to a hash entry, the value returned depends on the style of new
used to create the hash. In the first form, the access returns nil
. If obj is specified, this single object will be used for all default values. If a block is specified, it will be called with the hash object and the key, and should return the default value. It is the block’s responsibility to store the value in the hash if required.
h = Hash.new("Go Fish") h["a"] = 100 h["b"] = 200 h["a"] #=> 100 h["c"] #=> "Go Fish" # The following alters the single default object h["c"].upcase! #=> "GO FISH" h["d"] #=> "GO FISH" h.keys #=> ["a", "b"] # While this creates a new default object each time h = Hash.new { |hash, key| hash[key] = "Go Fish: #{key}" } h["c"] #=> "Go Fish: c" h["c"].upcase! #=> "GO FISH: C" h["d"] #=> "Go Fish: d" h.keys #=> ["c", "d"]
Create a new CGI
instance.
tag_maker
This is the same as using the options_hash
form with the value { :tag_maker => tag_maker }
Note that it is recommended to use the options_hash
form, since it also allows you specify the charset you will accept.
options_hash
A Hash
that recognizes three options:
:accept_charset
specifies encoding of received query string. If omitted, @@accept_charset
is used. If the encoding is not valid, a CGI::InvalidEncoding
will be raised.
Example. Suppose @@accept_charset
is “UTF-8”
when not specified:
cgi=CGI.new # @accept_charset # => "UTF-8"
when specified as “EUC-JP”:
cgi=CGI.new(:accept_charset => "EUC-JP") # => "EUC-JP"
:tag_maker
String
that specifies which version of the HTML generation methods to use. If not specified, no HTML generation methods will be loaded.
The following values are supported:
HTML 3.x
HTML 4.0
HTML 4.0 Transitional
HTML 4.0 with Framesets
HTML 5
:max_multipart_length
Specifies maximum length of multipart data. Can be an Integer
scalar or a lambda, that will be evaluated when the request is parsed. This allows more complex logic to be set when determining whether to accept multipart data (e.g. consult a registered users upload allowance)
Default is 128 * 1024 * 1024 bytes
cgi=CGI.new(:max_multipart_length => 268435456) # simple scalar cgi=CGI.new(:max_multipart_length => -> {check_filesystem}) # lambda
block
If provided, the block is called when an invalid encoding is encountered. For example:
encoding_errors={} cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value| encoding_errors[name] = value end
Finally, if the CGI
object is not created in a standard CGI
call environment (that is, it can’t locate REQUEST_METHOD in its environment), then it will run in “offline” mode. In this mode, it reads its parameters from the command line or (failing that) from standard input. Otherwise, cookies and other parameters are parsed automatically from the standard CGI
locations, which varies according to the REQUEST_METHOD.
This constructor will wrap either a String
or IO
object passed in data
for reading and/or writing. In addition to the CSV
instance methods, several IO
methods are delegated. (See CSV::open()
for a complete list.) If you pass a String
for data
, you can later retrieve it (after writing to it, for example) with CSV.string().
Note that a wrapped String
will be positioned at the beginning (for reading). If you want it at the end (for writing), use CSV::generate()
. If you want any other positioning, pass a preset StringIO
object instead.
You may set any reading and/or writing preferences in the options
Hash
. Available options are:
:col_sep
The String
placed between each field. This String
will be transcoded into the data’s Encoding
before parsing.
:row_sep
The String
appended to the end of each row. This can be set to the special :auto
setting, which requests that CSV
automatically discover this from the data. Auto-discovery reads ahead in the data looking for the next "\r\n"
, "\n"
, or "\r"
sequence. A sequence will be selected even if it occurs in a quoted field, assuming that you would have the same line endings there. If none of those sequences is found, data
is ARGF
, STDIN
, STDOUT
, or STDERR
, or the stream is only available for output, the default $INPUT_RECORD_SEPARATOR
($/
) is used. Obviously, discovery takes a little time. Set
manually if speed is important. Also note that IO
objects should be opened in binary mode on Windows if this feature will be used as the line-ending translation can cause problems with resetting the document position to where it was before the read ahead. This String
will be transcoded into the data’s Encoding
before parsing.
:quote_char
The character used to quote fields. This has to be a single character String
. This is useful for application that incorrectly use '
as the quote character instead of the correct "
. CSV
will always consider a double sequence of this character to be an escaped quote. This String
will be transcoded into the data’s Encoding
before parsing.
:field_size_limit
This is a maximum size CSV
will read ahead looking for the closing quote for a field. (In truth, it reads to the first line ending beyond this size.) If a quote cannot be found within the limit CSV
will raise a MalformedCSVError
, assuming the data is faulty. You can use this limit to prevent what are effectively DoS attacks on the parser. However, this limit can cause a legitimate parse to fail and thus is set to nil
, or off, by default.
:converters
An Array
of names from the Converters
Hash
and/or lambdas that handle custom conversion. A single converter doesn’t have to be in an Array
. All built-in converters try to transcode fields to UTF-8 before converting. The conversion will fail if the data cannot be transcoded, leaving the field unchanged.
:unconverted_fields
If set to true
, an unconverted_fields() method will be added to all returned rows (Array
or CSV::Row
) that will return the fields as they were before conversion. Note that :headers
supplied by Array
or String
were not fields of the document and thus will have an empty Array
attached.
:headers
If set to :first_row
or true
, the initial row of the CSV
file will be treated as a row of headers. If set to an Array
, the contents will be used as the headers. If set to a String
, the String
is run through a call of CSV::parse_line()
with the same :col_sep
, :row_sep
, and :quote_char
as this instance to produce an Array
of headers. This setting causes CSV#shift()
to return rows as CSV::Row
objects instead of Arrays and CSV#read()
to return CSV::Table
objects instead of an Array
of Arrays.
:return_headers
When false
, header rows are silently swallowed. If set to true
, header rows are returned in a CSV::Row
object with identical headers and fields (save that the fields do not go through the converters).
:write_headers
When true
and :headers
is set, a header row will be added to the output.
:header_converters
Identical in functionality to :converters
save that the conversions are only made to header rows. All built-in converters try to transcode headers to UTF-8 before converting. The conversion will fail if the data cannot be transcoded, leaving the header unchanged.
:skip_blanks
When set to a true
value, CSV
will skip over any empty rows. Note that this setting will not skip rows that contain column separators, even if the rows contain no actual data. If you want to skip rows that contain separators but no content, consider using :skip_lines
, or inspecting fields.compact.empty? on each row.
:force_quotes
When set to a true
value, CSV
will quote all CSV
fields it creates.
:skip_lines
When set to an object responding to match
, every line matching it is considered a comment and ignored during parsing. When set to a String
, it is first converted to a Regexp
. When set to nil
no line is considered a comment. If the passed object does not respond to match
, ArgumentError
is thrown.
:liberal_parsing
When set to a true
value, CSV
will attempt to parse input not conformant with RFC 4180, such as double quotes in unquoted fields.
:nil_value
When set an object, any values of an empty field are replaced by the set object, not nil.
:empty_value
When set an object, any values of a blank string field is replaced by the set object.
:quote_empty
TODO
:write_converters
TODO
:write_nil_value
TODO
:write_empty_value
TODO
:strip
TODO
See CSV::DEFAULT_OPTIONS
for the default settings.
Options cannot be overridden in the instance methods for performance reasons, so be sure to set what you want here.
Pass in the obj to delegate method calls to. All methods supported by obj will be delegated to.
Creates a new ACL
from list
with an evaluation order
of DENY_ALLOW
or ALLOW_DENY
.
An ACL
list
is an Array
of “allow” or “deny” and an address or address mask or “all” or “*” to match any address:
%w[
deny all
allow 192.0.2.2
allow 192.0.2.128/26
]
Constructs a new ERB
object with the template specified in str.
An ERB
object works by building a chunk of Ruby code that will output the completed template when run. If safe_level is set to a non-nil value, ERB
code will be run in a separate thread with $SAFE set to the provided level.
If trim_mode is passed a String
containing one or more of the following modifiers, ERB
will adjust its code generation as listed:
% enables Ruby code processing for lines beginning with % <> omit newline for lines starting with <% and ending in %> > omit newline for lines ending in %> - omit blank lines ending in -%>
eoutvar can be used to set the name of the variable ERB
will build up its output in. This is useful when you need to run multiple ERB
templates through the same binding and/or when you want to control where output ends up. Pass the name of the variable to be used inside a String
.
require "erb" # build data class class Listings PRODUCT = { :name => "Chicken Fried Steak", :desc => "A well messages pattie, breaded and fried.", :cost => 9.95 } attr_reader :product, :price def initialize( product = "", price = "" ) @product = product @price = price end def build b = binding # create and run templates, filling member data variables ERB.new(<<-'END_PRODUCT'.gsub(/^\s+/, ""), trim_mode: "", eoutvar: "@product").result b <%= PRODUCT[:name] %> <%= PRODUCT[:desc] %> END_PRODUCT ERB.new(<<-'END_PRICE'.gsub(/^\s+/, ""), trim_mode: "", eoutvar: "@price").result b <%= PRODUCT[:name] %> -- <%= PRODUCT[:cost] %> <%= PRODUCT[:desc] %> END_PRICE end end # setup template data listings = Listings.new listings.build puts listings.product + "\n" + listings.price
Generates
Chicken Fried Steak A well messages pattie, breaded and fried. Chicken Fried Steak -- 9.95 A well messages pattie, breaded and fried.
Set
up option processing.
The options to support are passed to new() as an array of arrays. Each sub-array contains any number of String
option names which carry the same meaning, and one of the following flags:
Option does not take an argument.
Option always takes an argument.
Option may or may not take an argument.
The first option name is considered to be the preferred (canonical) name. Other than that, the elements of each sub-array can be in any order.
Creates a new ipaddr object either from a human readable IP address representation in string, or from a packed in_addr
value followed by an address family.
In the former case, the following are the valid formats that will be recognized: “address”, “address/prefixlen” and “address/mask”, where IPv6 address may be enclosed in square brackets (‘[’ and ‘]’). If a prefixlen or a mask is specified, it returns a masked IP address. Although the address family is determined automatically from a specified string, you can specify one explicitly by the optional second argument.
Otherwise an IP address is generated from a packed in_addr
value and an address family.
The IPAddr
class defines many methods and operators, and some of those, such as &, |, include? and ==, accept a string, or a packed in_addr
value instead of an IPAddr
object.
Creates a new XMP
object.
The top-level binding or, optional bind
parameter will be used when creating the workspace. See WorkSpace.new for more information.
This uses the :XMP
prompt mode, see Customizing the IRB Prompt at IRB
for full detail.
logdev
The log device. This is a filename (String
) or IO
object (typically STDOUT
, STDERR
, or an open file).
shift_age
Number of old log files to keep, or frequency of rotation (daily
, weekly
or monthly
). Default value is 0.
shift_size
Maximum logfile size in bytes (only applies when shift_age
is a number). Defaults to 1048576
(1MB).
level
Logging severity threshold. Default values is Logger::DEBUG.
progname
Program name to include in log messages. Default value is nil.
formatter
Logging formatter. Default values is an instance of Logger::Formatter
.
datetime_format
Date
and time format. Default value is ‘%Y-%m-%d %H:%M:%S’.
shift_period_suffix
The log file suffix format for daily
, weekly
or monthly
rotation. Default is ‘%Y%m%d’.
Create an instance.
Matrix.new
is private; use Matrix.rows
, columns, [], etc… to create.
Vector.new
is private; use Vector[] or Vector.elements
to create.
Initializes the instance and yields itself if called with a block.
banner
Banner message.
width
Summary width.
indent
Summary indent.
Pushes a new List
.