Waits until IO
is writable without blocking and returns self
or nil
when times out.
Closes the write end of a duplex I/O stream (i.e., one that contains both a read and a write stream, such as a pipe). Will raise an IOError
if the stream is not duplexed.
f = IO.popen("/bin/sh","r+") f.close_write f.print "nowhere"
produces:
prog.rb:3:in `write': not opened for writing (IOError) from prog.rb:3:in `print' from prog.rb:3
Calling this method on closed IO
object is just ignored since Ruby 2.3.
Writes the given string to ios using the write(2) system call after O_NONBLOCK is set for the underlying file descriptor.
It returns the number of bytes written.
write_nonblock
just calls the write(2) system call. It causes all errors the write(2) system call causes: Errno::EWOULDBLOCK, Errno::EINTR, etc. The result may also be smaller than string.length (partial write). The caller should care such errors and partial write.
If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by IO::WaitWritable
. So IO::WaitWritable
can be used to rescue the exceptions for retrying write_nonblock.
# Creates a pipe. r, w = IO.pipe # write_nonblock writes only 65536 bytes and return 65536. # (The pipe size is 65536 bytes on this environment.) s = "a" * 100000 p w.write_nonblock(s) #=> 65536 # write_nonblock cannot write a byte and raise EWOULDBLOCK (EAGAIN). p w.write_nonblock("b") # Resource temporarily unavailable (Errno::EAGAIN)
If the write buffer is not empty, it is flushed at first.
When write_nonblock
raises an exception kind of IO::WaitWritable
, write_nonblock
should not be called until io is writable for avoiding busy loop. This can be done as follows.
begin result = io.write_nonblock(string) rescue IO::WaitWritable, Errno::EINTR IO.select(nil, [io]) retry end
Note that this doesn’t guarantee to write all data in string. The length written is reported as result and it should be checked later.
On some platforms such as Windows, write_nonblock
is not supported according to the kind of the IO
object. In such cases, write_nonblock
raises Errno::EBADF
.
By specifying a keyword argument exception to false
, you can indicate that write_nonblock
should not raise an IO::WaitWritable
exception, but return the symbol :wait_writable
instead.
Returns a hash representing information about named captures of rxp.
A key of the hash is a name of the named captures. A value of the hash is an array which is list of indexes of corresponding named captures.
/(?<foo>.)(?<bar>.)/.named_captures #=> {"foo"=>[1], "bar"=>[2]} /(?<foo>.)(?<foo>.)/.named_captures #=> {"foo"=>[1, 2]}
If there are no named captures, an empty hash is returned.
/(.)(.)/.named_captures #=> {}
USE OF RIPPER LIBRARY ONLY.
Strips up to width
leading whitespaces from input
, and returns the stripped column width.
USE OF RIPPER LIBRARY ONLY.
Strips up to width
leading whitespaces from input
, and returns the stripped column width.
Disallows further write using shutdown system call.
UNIXSocket.pair {|s1, s2| s1.print "ping" s1.close_write p s2.read #=> "ping" s2.print "pong" s2.close p s1.read #=> "pong" }
creates an Addrinfo
object from the arguments.
The arguments are interpreted as similar to self.
Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80) #=> #<Addrinfo: 221.186.184.68:80 TCP (www.ruby-lang.org:80)> Addrinfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2") #=> #<Addrinfo: /tmp/sock2 SOCK_STREAM>
Returns true for IPv4 private address (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16). It returns false otherwise.
Closes the write end of a StringIO
. Will raise an IOError
if the receiver is not writeable.
Returns true
if the stream is not writable, false
otherwise.
Returns string of return value type of method.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbooks') method = WIN32OLE_METHOD.new(tobj, 'Add') puts method.return_type # => Workbook
Returns number of return value type of method.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbooks') method = WIN32OLE_METHOD.new(tobj, 'Add') puts method.return_vtype # => 26
Returns variable kind string.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') variables = tobj.variables variables.each do |variable| puts "#{variable.name} #{variable.variable_kind}" end The result of above script is following: xlChart CONSTANT xlDialogSheet CONSTANT xlExcel4IntlMacroSheet CONSTANT xlExcel4MacroSheet CONSTANT xlWorksheet CONSTANT
Returns true
if headers will be returned as a row of results. See CSV::new
for details.
Returns true
if headers are written in output. See CSV::new
for details.
Returns a string containing the IP address representation in canonical form.
Returns the names of the binding’s local variables as symbols.
def foo a = 1 2.times do |n| binding.local_variables #=> [:a, :n] end end
This method is the short version of the following code:
binding.eval("local_variables")
Returns the Ruby source filename and line number of the binding object.