Returns a string representation of self
(not including the leading colon):
:foo.to_s # => "foo"
Symbol#id2name
is an alias for Symbol#to_s
.
Related: Symbol#inspect
, Symbol#name
.
The opposite of Pathname#absolute?
It returns false
if the pathname begins with a slash.
p = Pathname.new('/im/sure') p.relative? #=> false p = Pathname.new('not/so/sure') p.relative? #=> true
Returns the children of the directory (files and subdirectories, not recursive) as an array of Pathname
objects.
By default, the returned pathnames will have enough information to access the files. If you set with_directory
to false
, then the returned pathnames will contain the filename only.
For example:
pn = Pathname("/usr/lib/ruby/1.8") pn.children # -> [ Pathname:/usr/lib/ruby/1.8/English.rb, Pathname:/usr/lib/ruby/1.8/Env.rb, Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ] pn.children(false) # -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ]
Note that the results never contain the entries .
and ..
in the directory because they are not children.
Recursively deletes a directory, including all directories beneath it.
See FileUtils.rm_rf
Return the path as a String
.
to_path
is implemented so Pathname
objects are usable with File.open
, etc.
Returns the real (absolute) pathname for self
in the actual filesystem.
Does not contain symlinks or useless dots, ..
and .
.
All components of the pathname must exist when this method is called.
Returns the real (absolute) pathname of self
in the actual filesystem.
Does not contain symlinks or useless dots, ..
and .
.
The last component of the real pathname can be nonexistent.
Returns all the bytes from the file, or the first N
if specified.
See File.binread
.
See File.lstat
.
Tokenizes the Ruby program and returns an array of strings. The filename
and lineno
arguments are mostly ignored, since the return value is just the tokenized input. By default, this method does not handle syntax errors in src
, use the raise_errors
keyword to raise a SyntaxError
for an error in src
.
p Ripper.tokenize("def m(a) nil end") # => ["def", " ", "m", "(", "a", ")", " ", "nil", " ", "end"]
Return scanner state of current token.
Return the current token string.
Return true if parsed source has errors.
Listens for connections, using the specified int
as the backlog. A call to listen only applies if the socket
is of type SOCK_STREAM
or SOCK_SEQPACKET
.
backlog
- the maximum length of the queue for pending connections.
require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' ) socket.bind( sockaddr ) socket.listen( 5 )
require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) socket.listen( 1 )
On unix based systems the above will work because a new sockaddr
struct is created on the address ADDR_ANY, for an arbitrary port number as handed off by the kernel. It will not work on Windows, because Windows requires that the socket
is bound by calling bind before it can listen.
If the backlog amount exceeds the implementation-dependent maximum queue length, the implementation’s maximum queue length will be used.
On unix-based based systems the following system exceptions may be raised if the call to listen fails:
Errno::EBADF - the socket argument is not a valid file descriptor
Errno::EDESTADDRREQ - the socket is not bound to a local address, and the protocol does not support listening on an unbound socket
Errno::EINVAL - the socket is already connected
Errno::ENOTSOCK - the socket argument does not refer to a socket
Errno::EOPNOTSUPP - the socket protocol does not support listen
Errno::EACCES - the calling process does not have appropriate privileges
Errno::EINVAL - the socket has been shut down
Errno::ENOBUFS - insufficient resources are available in the system to complete the call
On Windows systems the following system exceptions may be raised if the call to listen fails:
Errno::ENETDOWN - the network is down
Errno::EADDRINUSE - the socket’s local address is already in use. This usually occurs during the execution of bind but could be delayed if the call to bind was to a partially wildcard address (involving ADDR_ANY) and if a specific address needs to be committed at the time of the call to listen
Errno::EINPROGRESS - a Windows Sockets 1.1 call is in progress or the service provider is still processing a callback function
Errno::EINVAL - the socket
has not been bound with a call to bind.
Errno::EISCONN - the socket
is already connected
Errno::EMFILE - no more socket descriptors are available
Errno::ENOBUFS - no buffer space is available
Errno::ENOTSOC - socket
is not a socket
Errno::EOPNOTSUPP - the referenced socket
is not a type that supports the listen method
listen manual pages on unix-based systems
listen function in Microsoft’s Winsock functions reference
Receives up to maxlen bytes from socket
. flags is zero or more of the MSG_
options. The first element of the results, mesg, is the data received. The second element, sender_addrinfo, contains protocol-specific address information of the sender.
maxlen
- the maximum number of bytes to receive from the socket
flags
- zero or more of the MSG_
options
# In one file, start this first require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' ) socket.bind( sockaddr ) socket.listen( 5 ) client, client_addrinfo = socket.accept data = client.recvfrom( 20 )[0].chomp puts "I only received 20 bytes '#{data}'" sleep 1 socket.close # In another file, start this second require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' ) socket.connect( sockaddr ) socket.puts "Watch this get cut short!" socket.close
On unix-based based systems the following system exceptions may be raised if the call to recvfrom fails:
Errno::EAGAIN - the socket
file descriptor is marked as O_NONBLOCK and no data is waiting to be received; or MSG_OOB
is set and no out-of-band data is available and either the socket
file descriptor is marked as O_NONBLOCK or the socket
does not support blocking to wait for out-of-band-data
Errno::EWOULDBLOCK - see Errno::EAGAIN
Errno::EBADF - the socket
is not a valid file descriptor
Errno::ECONNRESET - a connection was forcibly closed by a peer
Errno::EFAULT - the socket’s internal buffer, address or address length cannot be accessed or written
Errno::EINTR - a signal interrupted recvfrom before any data was available
Errno::EINVAL - the MSG_OOB
flag is set and no out-of-band data is available
Errno::EIO - an i/o error occurred while reading from or writing to the filesystem
Errno::ENOBUFS - insufficient resources were available in the system to perform the operation
Errno::ENOMEM - insufficient memory was available to fulfill the request
Errno::ENOSR - there were insufficient STREAMS resources available to complete the operation
Errno::ENOTCONN - a receive is attempted on a connection-mode socket that is not connected
Errno::ENOTSOCK - the socket
does not refer to a socket
Errno::EOPNOTSUPP - the specified flags are not supported for this socket type
Errno::ETIMEDOUT - the connection timed out during connection establishment or due to a transmission timeout on an active connection
On Windows systems the following system exceptions may be raised if the call to recvfrom fails:
Errno::ENETDOWN - the network is down
Errno::EFAULT - the internal buffer and from parameters on socket
are not part of the user address space, or the internal fromlen parameter is too small to accommodate the peer address
Errno::EINTR - the (blocking) call was cancelled by an internal call to the WinSock function WSACancelBlockingCall
Errno::EINPROGRESS - a blocking Windows Sockets 1.1 call is in progress or the service provider is still processing a callback function
Errno::EINVAL - socket
has not been bound with a call to bind, or an unknown flag was specified, or MSG_OOB
was specified for a socket with SO_OOBINLINE
enabled, or (for byte stream-style sockets only) the internal len parameter on socket
was zero or negative
Errno::EISCONN - socket
is already connected. The call to recvfrom is not permitted with a connected socket on a socket that is connection oriented or connectionless.
Errno::ENETRESET - the connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.
Errno::EOPNOTSUPP - MSG_OOB
was specified, but socket
is not stream-style such as type SOCK_STREAM
. OOB data is not supported in the communication domain associated with socket
, or socket
is unidirectional and supports only send operations
Errno::ESHUTDOWN - socket
has been shutdown. It is not possible to call recvfrom on a socket after shutdown has been invoked.
Errno::EWOULDBLOCK - socket
is marked as nonblocking and a call to recvfrom would block.
Errno::EMSGSIZE - the message was too large to fit into the specified buffer and was truncated.
Errno::ETIMEDOUT - the connection has been dropped, because of a network failure or because the system on the other end went down without notice
Errno::ECONNRESET - the virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket; it is no longer usable. On a UDP-datagram socket this error indicates a previous send operation resulted in an ICMP Port Unreachable message.