Returns the Encoding
object that represents the encoding of obj.
In general, to_sym
returns the Symbol
corresponding to an object. As sym is already a symbol, self
is returned in this case.
Returns sym.to_s.match
.
Returns sym.to_s.match?
.
Returns the Encoding
object that represents the encoding of sym.
Callback invoked whenever a subclass of the current class is created.
Example:
class Foo def self.inherited(subclass) puts "New subclass: #{subclass}" end end class Bar < Foo end class Baz < Bar end
produces:
New subclass: Bar New subclass: Baz
Returns true
if self
points to a mountpoint.
Joins the given pathnames onto self
to create a new Pathname
object.
path0 = Pathname.new("/usr") # Pathname:/usr path0 = path0.join("bin/ruby") # Pathname:/usr/bin/ruby # is the same as path1 = Pathname.new("/usr") + "bin/ruby" # Pathname:/usr/bin/ruby path0 == path1 #=> true
Iterates over the directory tree in a depth first manner, yielding a Pathname
for each file under “this” directory.
Returns an Enumerator
if no block is given.
Since it is implemented by the standard library module Find
, Find.prune
can be used to control the traversal.
If self
is .
, yielded pathnames begin with a filename in the current directory, not ./
.
See Find.find
Returns all the bytes from the file, or the first N
if specified.
See File.binread
.
Removes a file or directory, using File.unlink
if self
is a file, or Dir.unlink
as necessary.
This method is called when strong warning is produced by the parser. fmt
and args
is printf style.
Return line number of current parsing line. This number starts from 1.
Return encoding of the source.
Returns a Hash
in which the key-value pairs have been inverted.
Example:
require 'sdbm' SDBM.open 'my_database' do |db| db.update('apple' => 'fruit', 'spinach' => 'vegetable') db.invert #=> {"fruit" => "apple", "vegetable" => "spinach"} end
Returns true
if the database contains the given key
.
Binds to the given local address.
local_sockaddr
- the struct
sockaddr contained in a string or an Addrinfo
object
require 'socket' # use Addrinfo socket = Socket.new(:INET, :STREAM, 0) socket.bind(Addrinfo.tcp("127.0.0.1", 2222)) p socket.local_address #=> #<Addrinfo: 127.0.0.1:2222 TCP> # use struct sockaddr include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' ) socket.bind( sockaddr )
On unix-based based systems the following system exceptions may be raised if the call to bind fails:
Errno::EACCES - the specified sockaddr is protected and the current user does not have permission to bind to it
Errno::EADDRINUSE - the specified sockaddr is already in use
Errno::EADDRNOTAVAIL - the specified sockaddr is not available from the local machine
Errno::EAFNOSUPPORT - the specified sockaddr is not a valid address for the family of the calling socket
Errno::EBADF - the sockaddr specified is not a valid file descriptor
Errno::EFAULT - the sockaddr argument cannot be accessed
Errno::EINVAL - the socket
is already bound to an address, and the protocol does not support binding to the new sockaddr or the socket
has been shut down.
Errno::EINVAL - the address length is not a valid length for the address family
Errno::ENAMETOOLONG - the pathname resolved had a length which exceeded PATH_MAX
Errno::ENOBUFS - no buffer space is available
Errno::ENOSR - there were insufficient STREAMS resources available to complete the operation
Errno::ENOTSOCK - the socket
does not refer to a socket
Errno::EOPNOTSUPP - the socket type of the socket
does not support binding to an address
On unix-based based systems if the address family of the calling socket
is Socket::AF_UNIX
the follow exceptions may be raised if the call to bind fails:
Errno::EACCES - search permission is denied for a component of the prefix path or write access to the socket
is denied
Errno::EDESTADDRREQ - the sockaddr argument is a null pointer
Errno::EISDIR - same as Errno::EDESTADDRREQ
Errno::EIO - an i/o error occurred
Errno::ELOOP - too many symbolic links were encountered in translating the pathname in sockaddr
Errno::ENAMETOOLLONG - a component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters
Errno::ENOENT - a component of the pathname does not name an existing file or the pathname is an empty string
Errno::ENOTDIR - a component of the path prefix of the pathname in sockaddr is not a directory
Errno::EROFS - the name would reside on a read only filesystem
On Windows systems the following system exceptions may be raised if the call to bind fails:
Errno::ENETDOWN– the network is down
Errno::EACCES - the attempt to connect the datagram socket to the broadcast address failed
Errno::EADDRINUSE - the socket’s local address is already in use
Errno::EADDRNOTAVAIL - the specified address is not a valid address for this computer
Errno::EFAULT - the socket’s internal address or address length parameter is too small or is not a valid part of the user space addressed
Errno::EINVAL - the socket
is already bound to an address
Errno::ENOBUFS - no buffer space is available
Errno::ENOTSOCK - the socket
argument does not refer to a socket
bind manual pages on unix-based systems
bind function in Microsoft’s Winsock functions reference
Obtains address information for nodename:servname.
Note that Addrinfo.getaddrinfo
provides the same functionality in an object oriented style.
family should be an address family such as: :INET, :INET6, etc.
socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
protocol should be a protocol defined in the family, and defaults to 0 for the family.
flags should be bitwise OR of Socket::AI_* constants.
Socket.getaddrinfo("www.ruby-lang.org", "http", nil, :STREAM) #=> [["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68", 2, 1, 6]] # PF_INET/SOCK_STREAM/IPPROTO_TCP Socket.getaddrinfo("localhost", nil) #=> [["AF_INET", 0, "localhost", "127.0.0.1", 2, 1, 6], # PF_INET/SOCK_STREAM/IPPROTO_TCP # ["AF_INET", 0, "localhost", "127.0.0.1", 2, 2, 17], # PF_INET/SOCK_DGRAM/IPPROTO_UDP # ["AF_INET", 0, "localhost", "127.0.0.1", 2, 3, 0]] # PF_INET/SOCK_RAW/IPPROTO_IP
reverse_lookup directs the form of the third element, and has to be one of below. If reverse_lookup is omitted, the default value is nil
.
+true+, +:hostname+: hostname is obtained from numeric address using reverse lookup, which may take a time. +false+, +:numeric+: hostname is same as numeric address. +nil+: obey to the current +do_not_reverse_lookup+ flag.
If Addrinfo
object is preferred, use Addrinfo.getaddrinfo
.