Results for: "OptionParser"

See IO.sysopen.

Returns the last access time for the file.

See File.atime.

Returns the birth time for the file. If the platform doesn’t have birthtime, raises NotImplementedError.

See File.birthtime.

Returns the last change time, using directory information, not the file itself.

See File.ctime.

Returns the last modified time of the file.

See File.mtime.

Opens the file for reading or writing.

See File.open.

Update the access and modification times of the file.

See File.utime.

Update the access and modification times of the file.

Same as Pathname#utime, but does not follow symbolic links.

See File.lutime.

Returns the last component of the path.

See File.basename.

See FileTest.chardev?.

See FileTest.setuid?.

See FileTest.setgid?.

See FileTest.sticky?.

See FileTest.zero?.

Tests the file is empty.

See Dir#empty? and FileTest.empty?.

Opens the referenced directory.

See Dir.open.

Spawns the specified command on a newly allocated pty. You can also use the alias ::getpty.

The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.

env is an optional hash that provides additional environment variables to the spawned pty.

# sets FOO to "bar"
PTY.spawn({"FOO"=>"bar"}, "printenv", "FOO") do |r, w, pid|
  p r.read #=> "bar\r\n"
ensure
  r.close; w.close; Process.wait(pid)
end
# unsets FOO
PTY.spawn({"FOO"=>nil}, "printenv", "FOO") do |r, w, pid|
  p r.read #=> ""
ensure
  r.close; w.close; Process.wait(pid)
end

command and command_line are the full commands to run, given a String. Any additional arguments will be passed to the command.

Return values

In the non-block form this returns an array of size three, [r, w, pid].

In the block form these same values will be yielded to the block:

r

A readable IO that contains the command’s standard output and standard error

w

A writable IO that is the command’s standard input

pid

The process identifier for the command.

Clean up

This method does not clean up like closing IOs or waiting for child process, except that the process is detached in the block form to prevent it from becoming a zombie (see Process.detach). Any other cleanup is the responsibility of the caller. If waiting for pid, be sure to close both r and w before doing so; doing it in the reverse order may cause deadlock on some OSes.

Allocates a pty (pseudo-terminal).

In the block form, yields an array of two elements (master_io, slave_file) and the value of the block is returned from open.

The IO and File are both closed after the block completes if they haven’t been already closed.

PTY.open {|master, slave|
  p master      #=> #<IO:masterpty:/dev/pts/1>
  p slave      #=> #<File:/dev/pts/1>
  p slave.path #=> "/dev/pts/1"
}

In the non-block form, returns a two element array, [master_io, slave_file].

master, slave = PTY.open
# do something with master for IO, or the slave file

The arguments in both forms are:

master_io

the master of the pty, as an IO.

slave_file

the slave of the pty, as a File. The path to the terminal device is available via slave_file.path

IO#raw! is usable to disable newline conversions:

require 'io/console'
PTY.open {|m, s|
  s.raw!
  # ...
}

Spawns the specified command on a newly allocated pty. You can also use the alias ::getpty.

The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.

env is an optional hash that provides additional environment variables to the spawned pty.

# sets FOO to "bar"
PTY.spawn({"FOO"=>"bar"}, "printenv", "FOO") do |r, w, pid|
  p r.read #=> "bar\r\n"
ensure
  r.close; w.close; Process.wait(pid)
end
# unsets FOO
PTY.spawn({"FOO"=>nil}, "printenv", "FOO") do |r, w, pid|
  p r.read #=> ""
ensure
  r.close; w.close; Process.wait(pid)
end

command and command_line are the full commands to run, given a String. Any additional arguments will be passed to the command.

Return values

In the non-block form this returns an array of size three, [r, w, pid].

In the block form these same values will be yielded to the block:

r

A readable IO that contains the command’s standard output and standard error

w

A writable IO that is the command’s standard input

pid

The process identifier for the command.

Clean up

This method does not clean up like closing IOs or waiting for child process, except that the process is detached in the block form to prevent it from becoming a zombie (see Process.detach). Any other cleanup is the responsibility of the caller. If waiting for pid, be sure to close both r and w before doing so; doing it in the reverse order may cause deadlock on some OSes.

This method is called when weak warning is produced by the parser. fmt and args is printf style.

This method is called when strong warning is produced by the parser. fmt and args is printf style.

EXPERIMENTAL

Parses src and create S-exp tree. Returns more readable tree rather than Ripper.sexp_raw. This method is mainly for developer use. The filename argument is mostly ignored. By default, this method does not handle syntax errors in src, returning nil in such cases. Use the raise_errors keyword to raise a SyntaxError for an error in src.

require 'ripper'
require 'pp'

pp Ripper.sexp("def m(a) nil end")
  #=> [:program,
       [[:def,
        [:@ident, "m", [1, 4]],
        [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil, nil, nil]],
        [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]

enable the socket option IPV6_V6ONLY if IPV6_V6ONLY is available.

Requests a connection to be made on the given remote_sockaddr. Returns 0 if successful, otherwise an exception is raised.

Parameter

Example:

# Pull down Google's web page
require 'socket'
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 80, 'www.google.com' )
socket.connect( sockaddr )
socket.write( "GET / HTTP/1.0\r\n\r\n" )
results = socket.read

Unix-based Exceptions

On unix-based systems the following system exceptions may be raised if the call to connect fails:

On unix-based systems if the address family of the calling socket is AF_UNIX the follow exceptions may be raised if the call to connect fails:

Windows Exceptions

On Windows systems the following system exceptions may be raised if the call to connect fails:

See

Accepts a next connection. Returns a new Socket object and Addrinfo object.

serv = Socket.new(:INET, :STREAM, 0)
serv.listen(5)
c = Socket.new(:INET, :STREAM, 0)
c.connect(serv.connect_address)
p serv.accept #=> [#<Socket:fd 6>, #<Addrinfo: 127.0.0.1:48555 TCP>]
Search took: 7ms  ·  Total Results: 6041