Create a Pathname
object from the given String
(or String-like object). If path
contains a NULL character (\0
), an ArgumentError
is raised.
Create a new Ripper
object. src must be a String
, an IO
, or an Object
which has gets
method.
This method does not starts parsing. See also Ripper#parse
and Ripper.parse
.
Creates a new socket object.
domain should be a communications domain such as: :INET, :INET6, :UNIX, etc.
socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
protocol is optional and should be a protocol defined in the domain. If protocol is not given, 0 is used internally.
Socket.new(:INET, :STREAM) # TCP socket Socket.new(:INET, :DGRAM) # UDP socket Socket.new(:UNIX, :STREAM) # UNIX stream socket Socket.new(:UNIX, :DGRAM) # UNIX datagram socket
returns a new instance of Addrinfo
. The instance contains sockaddr, family, socktype, protocol. sockaddr means struct sockaddr which can be used for connect(2), etc. family, socktype and protocol are integers which is used for arguments of socket(2).
sockaddr is specified as an array or a string. The array should be compatible to the value of IPSocket#addr
or UNIXSocket#addr
. The string should be struct sockaddr as generated by Socket.sockaddr_in
or Socket.unpack_sockaddr_un
.
sockaddr examples:
Socket.sockaddr_in
(“smtp”, “2001:DB8::1”)
Socket.sockaddr_in
(80, “172.18.22.42”)
Socket.sockaddr_un
(“/tmp/sock”)
In an AF_INET/AF_INET6 sockaddr array, the 4th element, numeric IP address, is used to construct socket address in the Addrinfo
instance. If the 3rd element, textual host name, is non-nil, it is also recorded but used only for Addrinfo#inspect
.
family is specified as an integer to specify the protocol family such as Socket::PF_INET. It can be a symbol or a string which is the constant name with or without PF_ prefix such as :INET, :INET6, :UNIX, “PF_INET”, etc. If omitted, PF_UNSPEC is assumed.
socktype is specified as an integer to specify the socket type such as Socket::SOCK_STREAM. It can be a symbol or a string which is the constant name with or without SOCK_ prefix such as :STREAM, :DGRAM, :RAW, “SOCK_STREAM”, etc. If omitted, 0 is assumed.
protocol is specified as an integer to specify the protocol such as Socket::IPPROTO_TCP. It must be an integer, unlike family and socktype. If omitted, 0 is assumed. Note that 0 is reasonable value for most protocols, except raw socket.
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.
The SOCKS server configuration varies by implementation
When using the Dante libsocks/libsocksd implementation it is configured as SOCKS_SERVER env var.
See: manpages.debian.org/testing/dante-client/socksify.1.en.html for full env variable support.
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.
specify the timeout in seconds.
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
.
If fixed_anchor
is true
, \A
always matches the beginning of the string. Otherwise, \A
always matches the current position.
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.
Returns a new empty Hash object.
The initial default value and initial default proc for the new hash depend on which form above was used. See Default Values.
If neither an argument nor a block given, initializes both the default value and the default proc to nil
:
h = Hash.new h.default # => nil h.default_proc # => nil
If argument default_value
given but no block given, initializes the default value to the given default_value
and the default proc to nil
:
h = Hash.new(false) h.default # => false h.default_proc # => nil
If a block given but no argument, stores the block as the default proc and sets the default value to nil
:
h = Hash.new {|hash, key| "Default value for #{key}" } h.default # => nil h.default_proc.class # => Proc h[:nosuch] # => "Default value for nosuch"
Returns the new CSV object created using string
or io
and the specified options
.
Argument string
should be a String object; it will be put into a new StringIO
object positioned at the beginning.
Argument io
should be an IO
object that is:
Open for reading; on return, the IO
object will be closed.
Positioned at the beginning. To position at the end, for appending, use method CSV.generate
. For any other positioning, pass a preset StringIO object instead.
Argument options
: See:
For performance reasons, the options cannot be overridden in a CSV object, so those specified here will endure.
In addition to the CSV instance methods, several IO methods are delegated. See Delegated Methods.
Create a CSV object from a String object:
csv = CSV.new('foo,0') csv # => #<CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"">
Create a CSV object from a File object:
File.write('t.csv', 'foo,0') csv = CSV.new(File.open('t.csv')) csv # => #<CSV io_type:File io_path:"t.csv" encoding:UTF-8 lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"">
Raises an exception if the argument is nil
:
# Raises ArgumentError (Cannot parse nil as CSV): CSV.new(nil)
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 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
), IO
object (typically STDOUT
, STDERR
, or an open file), nil
(it writes nothing) or File::NULL
(same as nil
).
shift_age
Number of old log files to keep, or frequency of rotation (daily
, weekly
or monthly
). Default value is 0, which disables log file rotation.
shift_size
Maximum logfile size in bytes (only applies when shift_age
is a positive Integer
). 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’.
binmode
Use binary mode on the log device. Default value is false.
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 ::rows
, ::columns
, ::[]
, etc… to create.