Puts stream into binary mode. See IO#binmode
.
Puts ARGF
into binary mode. Once a stream is in binary mode, it cannot be reset to non-binary mode. This option has the following effects:
Newline conversion is disabled.
Encoding
conversion is disabled.
Content is treated as ASCII-8BIT.
Returns true if ARGF
is being read in binary mode; false otherwise. To enable binary mode use ARGF.binmode
.
For example:
ARGF.binmode? #=> false ARGF.binmode ARGF.binmode? #=> true
Returns a BubbleBabble encoded version of a given string.
Changes permission bits on the named files (in list
) to the bit pattern represented by mode
.
mode
is the symbolic and absolute mode can be used.
Absolute mode is
FileUtils.chmod 0755, 'somecommand' FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb) FileUtils.chmod 0755, '/usr/bin/ruby', verbose: true
Symbolic mode is
FileUtils.chmod "u=wrx,go=rx", 'somecommand' FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb) FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', verbose: true
is user, group, other mask.
is user’s mask.
is group’s mask.
is other’s mask.
is write permission.
is read permission.
is execute permission.
is execute permission for directories only, must be used in conjunction with “+”
is uid, gid.
is sticky bit.
is added to a class given the specified mode.
Is removed from a given class given mode.
Is the exact nature of the class will be given a specified mode.
Changes permission bits on the named files (in list
) to the bit pattern represented by mode
.
mode
is the symbolic and absolute mode can be used.
Absolute mode is
FileUtils.chmod 0755, 'somecommand' FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb) FileUtils.chmod 0755, '/usr/bin/ruby', verbose: true
Symbolic mode is
FileUtils.chmod "u=wrx,go=rx", 'somecommand' FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb) FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', verbose: true
is user, group, other mask.
is user’s mask.
is group’s mask.
is other’s mask.
is write permission.
is read permission.
is execute permission.
is execute permission for directories only, must be used in conjunction with “+”
is uid, gid.
is sticky bit.
is added to a class given the specified mode.
Is removed from a given class given mode.
Is the exact nature of the class will be given a specified mode.
Changes permission bits on the named files (in list
) to the bit pattern represented by mode
.
FileUtils.chmod_R 0700, "/tmp/app.#{$$}" FileUtils.chmod_R "u=wrx", "/tmp/app.#{$$}"
Changes permission bits on the named files (in list
) to the bit pattern represented by mode
.
FileUtils.chmod_R 0700, "/tmp/app.#{$$}" FileUtils.chmod_R "u=wrx", "/tmp/app.#{$$}"
Calls the block with each repeated permutation of length n
of the elements of self
; each permutation is an Array; returns self
. The order of the permutations is indeterminate.
When a block and a positive Integer argument n
are given, calls the block with each n
-tuple repeated permutation of the elements of self
. The number of permutations is self.size**n
.
n
= 1:
a = [0, 1, 2] a.repeated_permutation(1) {|permutation| p permutation }
Output:
[0] [1] [2]
n
= 2:
a.repeated_permutation(2) {|permutation| p permutation }
Output:
[0, 0] [0, 1] [0, 2] [1, 0] [1, 1] [1, 2] [2, 0] [2, 1] [2, 2]
If n
is zero, calls the block once with an empty Array.
If n
is negative, does not call the block:
a.repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
Returns a new Enumerator if no block given:
a = [0, 1, 2] a.repeated_permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
Using Enumerators, it’s convenient to show the permutations and counts for some values of n
:
e = a.repeated_permutation(0) e.size # => 1 e.to_a # => [[]] e = a.repeated_permutation(1) e.size # => 3 e.to_a # => [[0], [1], [2]] e = a.repeated_permutation(2) e.size # => 9 e.to_a # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
Calls the block with each repeated combination of length n
of the elements of self
; each combination is an Array; returns self
. The order of the combinations is indeterminate.
When a block and a positive Integer argument n
are given, calls the block with each n
-tuple repeated combination of the elements of self
. The number of combinations is (n+1)(n+2)/2
.
n
= 1:
a = [0, 1, 2] a.repeated_combination(1) {|combination| p combination }
Output:
[0] [1] [2]
n
= 2:
a.repeated_combination(2) {|combination| p combination }
Output:
[0, 0] [0, 1] [0, 2] [1, 1] [1, 2] [2, 2]
If n
is zero, calls the block once with an empty Array.
If n
is negative, does not call the block:
a.repeated_combination(-1) {|combination| fail 'Cannot happen' }
Returns a new Enumerator if no block given:
a = [0, 1, 2] a.repeated_combination(2) # => #<Enumerator: [0, 1, 2]:combination(2)>
Using Enumerators, it’s convenient to show the combinations and counts for some values of n
:
e = a.repeated_combination(0) e.size # => 1 e.to_a # => [[]] e = a.repeated_combination(1) e.size # => 3 e.to_a # => [[0], [1], [2]] e = a.repeated_combination(2) e.size # => 6 e.to_a # => [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]
Like backtrace
, but returns each line of the execution stack as a Thread::Backtrace::Location
. Accepts the same arguments as backtrace
.
f = Fiber.new { Fiber.yield } f.resume loc = f.backtrace_locations.first loc.label #=> "yield" loc.path #=> "test.rb" loc.lineno #=> 1
Returns any backtrace associated with the exception. This method is similar to Exception#backtrace
, but the backtrace is an array of Thread::Backtrace::Location
.
This method is not affected by Exception#set_backtrace()
.
Requests a connection to be made on the given remote_sockaddr
after O_NONBLOCK is set for the underlying file descriptor. Returns 0 if successful, otherwise an exception is raised.
# +remote_sockaddr+ - the +struct+ sockaddr contained in a string or Addrinfo object
# Pull down Google's web page require 'socket' include Socket::Constants socket = Socket.new(AF_INET, SOCK_STREAM, 0) sockaddr = Socket.sockaddr_in(80, 'www.google.com') begin # emulate blocking connect socket.connect_nonblock(sockaddr) rescue IO::WaitWritable IO.select(nil, [socket]) # wait 3-way handshake completion begin socket.connect_nonblock(sockaddr) # check connection failure rescue Errno::EISCONN end end socket.write("GET / HTTP/1.0\r\n\r\n") results = socket.read
Refer to Socket#connect
for the exceptions that may be thrown if the call to connect_nonblock fails.
Socket#connect_nonblock
may raise any error corresponding to connect(2) failure, including Errno::EINPROGRESS.
If the exception is Errno::EINPROGRESS, it is extended by IO::WaitWritable
. So IO::WaitWritable
can be used to rescue the exceptions for retrying connect_nonblock.
By specifying a keyword argument exception to false
, you can indicate that connect_nonblock
should not raise an IO::WaitWritable
exception, but return the symbol :wait_writable
instead.
# Socket#connect
Returns the value that determines whether unconverted fields are to be available; used for parsing; see {Option unconverted_fields
}:
CSV.new('').unconverted_fields? # => nil
Set options. Takes the same argument as GetoptLong.new
.
Raises a RuntimeError
if option processing has already started.
‘get_option’ is an alias of ‘get’.
‘each_option’ is an alias of ‘each’.
Returns the Ruby source filename and line number of the binding object.
Returns additional info.
List of options that will be supplied to RDoc
Returns the Ruby source filename and line number containing this proc or nil
if this proc was not defined in Ruby (i.e. native).