Takes a token and gets the next token in the Negotiate authentication chain. Token can be Base64
encoded or not. The token can include the “Negotiate” header and it will be stripped. Does not indicate if SEC_I_CONTINUE or SEC_E_OK was returned. Token returned is Base64
encoded w/ all new lines removed.
Extracts the certificate chain from the spec
and calls verify
to ensure the signatures and certificate chain is valid according to the policy..
Get all [gem, version] from the command line.
An argument in the form gem:ver is pull apart into the gen name and version, respectively.
Returns the element at Integer offset index
; does not modify self
.
a = [:foo, 'bar', 2] a.at(0) # => :foo a.at(2) # => 2
Adds to array
all elements from each Array in other_arrays
; returns self
:
a = [0, 1] a.concat([2, 3], [4, 5]) # => [0, 1, 2, 3, 4, 5]
Returns the count of elements in self
.
Returns a new Array formed from self
with elements rotated from one end to the other.
When no argument given, returns a new Array that is like self
, except that the first element has been rotated to the last position:
a = [:foo, 'bar', 2, 'bar'] a1 = a.rotate a1 # => ["bar", 2, "bar", :foo]
When given a non-negative Integer count
, returns a new Array with count
elements rotated from the beginning to the end:
a = [:foo, 'bar', 2] a1 = a.rotate(2) a1 # => [2, :foo, "bar"]
If count
is large, uses count % array.size
as the count:
a = [:foo, 'bar', 2] a1 = a.rotate(20) a1 # => [2, :foo, "bar"]
If count
is zero, returns a copy of self
, unmodified:
a = [:foo, 'bar', 2] a1 = a.rotate(0) a1 # => [:foo, "bar", 2]
When given a negative Integer count
, rotates in the opposite direction, from end to beginning:
a = [:foo, 'bar', 2] a1 = a.rotate(-2) a1 # => ["bar", 2, :foo]
If count
is small (far from zero), uses count % array.size
as the count:
a = [:foo, 'bar', 2] a1 = a.rotate(-5) a1 # => ["bar", 2, :foo]
Rotates self
in place by moving elements from one end to the other; returns self
.
When no argument given, rotates the first element to the last position:
a = [:foo, 'bar', 2, 'bar'] a.rotate! # => ["bar", 2, "bar", :foo]
When given a non-negative Integer count
, rotates count
elements from the beginning to the end:
a = [:foo, 'bar', 2] a.rotate!(2) a # => [2, :foo, "bar"]
If count
is large, uses count % array.size
as the count:
a = [:foo, 'bar', 2] a.rotate!(20) a # => [2, :foo, "bar"]
If count
is zero, returns self
unmodified:
a = [:foo, 'bar', 2] a.rotate!(0) a # => [:foo, "bar", 2]
When given a negative Integer
count
, rotates in the opposite direction, from end to beginning:
a = [:foo, 'bar', 2] a.rotate!(-2) a # => ["bar", 2, :foo]
If count
is small (far from zero), uses count % array.size
as the count:
a = [:foo, 'bar', 2] a.rotate!(-5) a # => ["bar", 2, :foo]
Returns a new Array containing all non-nil
elements from self
:
a = [nil, 0, nil, 1, nil, 2, nil] a.compact # => [0, 1, 2]
Removes all nil
elements from self
.
Returns self
if any elements removed, otherwise nil
.
Returns a new Array that is a recursive flattening of self
:
Each non-Array element is unchanged.
Each Array is replaced by its individual elements.
With non-negative Integer argument level
, flattens recursively through level
levels:
a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten(0) # => [0, [1, [2, 3], 4], 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten(1) # => [0, 1, [2, 3], 4, 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten(2) # => [0, 1, 2, 3, 4, 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten(3) # => [0, 1, 2, 3, 4, 5]
With no argument, a nil
argument, or with negative argument level
, flattens all levels:
a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten # => [0, 1, 2, 3, 4, 5] [0, 1, 2].flatten # => [0, 1, 2] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten(-1) # => [0, 1, 2, 3, 4, 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten(-2) # => [0, 1, 2, 3, 4, 5] [0, 1, 2].flatten(-1) # => [0, 1, 2]
Replaces each nested Array in self
with the elements from that Array; returns self
if any changes, nil
otherwise.
With non-negative Integer argument level
, flattens recursively through level
levels:
a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten!(1) # => [0, 1, [2, 3], 4, 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten!(2) # => [0, 1, 2, 3, 4, 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten!(3) # => [0, 1, 2, 3, 4, 5] [0, 1, 2].flatten!(1) # => nil
With no argument, a nil
argument, or with negative argument level
, flattens all levels:
a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten! # => [0, 1, 2, 3, 4, 5] [0, 1, 2].flatten! # => nil a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten!(-1) # => [0, 1, 2, 3, 4, 5] a = [ 0, [ 1, [2, 3], 4 ], 5 ] a.flatten!(-2) # => [0, 1, 2, 3, 4, 5] [0, 1, 2].flatten!(-1) # => nil
When invoked with a block, yield all permutations of elements of self
; returns self
. The order of permutations is indeterminate.
When a block and an in-range positive Integer argument n
(0 < n <= self.size
) are given, calls the block with all n
-tuple permutations of self
.
Example:
a = [0, 1, 2] a.permutation(2) {|permutation| p permutation }
Output:
[0, 1] [0, 2] [1, 0] [1, 2] [2, 0] [2, 1]
Another example:
a = [0, 1, 2] a.permutation(3) {|permutation| p permutation }
Output:
[0, 1, 2] [0, 2, 1] [1, 0, 2] [1, 2, 0] [2, 0, 1] [2, 1, 0]
When n
is zero, calls the block once with a new empty Array:
a = [0, 1, 2] a.permutation(0) {|permutation| p permutation }
Output:
[]
When n
is out of range (negative or larger than self.size
), does not call the block:
a = [0, 1, 2] a.permutation(-1) {|permutation| fail 'Cannot happen' } a.permutation(4) {|permutation| fail 'Cannot happen' }
When a block given but no argument, behaves the same as a.permutation(a.size)
:
a = [0, 1, 2] a.permutation {|permutation| p permutation }
Output:
[0, 1, 2] [0, 2, 1] [1, 0, 2] [1, 2, 0] [2, 0, 1] [2, 1, 0]
Returns a new Enumerator if no block given:
a = [0, 1, 2] a.permutation # => #<Enumerator: [0, 1, 2]:permutation> a.permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
Returns random elements from self
.
When no arguments are given, returns a random element from self
:
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.sample # => 3 a.sample # => 8
If self
is empty, returns nil
.
When argument n
is given, returns a new Array containing n
random elements from self
:
a.sample(3) # => [8, 9, 2] a.sample(6) # => [9, 6, 10, 3, 1, 4]
Returns no more than a.size
elements (because no new duplicates are introduced):
a.sample(a.size * 2) # => [6, 4, 1, 8, 5, 9, 10, 2, 3, 7]
But self
may contain duplicates:
a = [1, 1, 1, 2, 2, 3] a.sample(a.size * 2) # => [1, 1, 3, 2, 1, 2]
The argument n
must be a non-negative numeric value. The order of the result array is unrelated to the order of self
. Returns a new empty Array if self
is empty.
The optional random
argument will be used as the random number generator:
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.sample(random: Random.new(1)) #=> 6 a.sample(4, random: Random.new(1)) #=> [6, 10, 9, 2]
Packs the contents of arr into a binary sequence according to the directives in aTemplateString (see the table below) Directives “A,” “a,” and “Z” may be followed by a count, which gives the width of the resulting field. The remaining directives also may take a count, indicating the number of array elements to convert. If the count is an asterisk (“*
”), all remaining array elements will be converted. Any of the directives “sSiIlL
” may be followed by an underscore (“_
”) or exclamation mark (“!
”) to use the underlying platform’s native size for the specified type; otherwise, they use a platform-independent size. Spaces are ignored in the template string. See also String#unpack
.
a = [ "a", "b", "c" ] n = [ 65, 66, 67 ] a.pack("A3A3A3") #=> "a b c " a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000" n.pack("ccc") #=> "ABC"
If aBufferString is specified and its capacity is enough, pack
uses it as the buffer and returns it. When the offset is specified by the beginning of aTemplateString, the result is filled after the offset. If original contents of aBufferString exists and it’s longer than the offset, the rest of offsetOfBuffer are overwritten by the result. If it’s shorter, the gap is filled with “\0
”.
# packed data is appended by default [255].pack("C", buffer:"foo".b) #=> "foo\xFF" # "@0" (offset 0) specifies that packed data is filled from beginning. # Also, original data after packed data is removed. ("oo" is removed.) [255].pack("@0C", buffer:"foo".b) #=> "\xFF" # If the offset is bigger than the original length, \x00 is filled. [255].pack("@5C", buffer:"foo".b) #=> "foo\x00\x00\xFF"
Note that “buffer:” option does not guarantee not to allocate memory in pack
. If the capacity of aBufferString is not enough, pack
allocates memory.
Directives for pack
.
Integer | Array | Directive | Element | Meaning ---------------------------------------------------------------------------- C | Integer | 8-bit unsigned (unsigned char) S | Integer | 16-bit unsigned, native endian (uint16_t) L | Integer | 32-bit unsigned, native endian (uint32_t) Q | Integer | 64-bit unsigned, native endian (uint64_t) J | Integer | pointer width unsigned, native endian (uintptr_t) | | (J is available since Ruby 2.3.) | | c | Integer | 8-bit signed (signed char) s | Integer | 16-bit signed, native endian (int16_t) l | Integer | 32-bit signed, native endian (int32_t) q | Integer | 64-bit signed, native endian (int64_t) j | Integer | pointer width signed, native endian (intptr_t) | | (j is available since Ruby 2.3.) | | S_ S! | Integer | unsigned short, native endian I I_ I! | Integer | unsigned int, native endian L_ L! | Integer | unsigned long, native endian Q_ Q! | Integer | unsigned long long, native endian (ArgumentError | | if the platform has no long long type.) | | (Q_ and Q! is available since Ruby 2.1.) J! | Integer | uintptr_t, native endian (same with J) | | (J! is available since Ruby 2.3.) | | s_ s! | Integer | signed short, native endian i i_ i! | Integer | signed int, native endian l_ l! | Integer | signed long, native endian q_ q! | Integer | signed long long, native endian (ArgumentError | | if the platform has no long long type.) | | (q_ and q! is available since Ruby 2.1.) j! | Integer | intptr_t, native endian (same with j) | | (j! is available since Ruby 2.3.) | | S> s> S!> s!> | Integer | same as the directives without ">" except L> l> L!> l!> | | big endian I!> i!> | | (available since Ruby 1.9.3) Q> q> Q!> q!> | | "S>" is the same as "n" J> j> J!> j!> | | "L>" is the same as "N" | | S< s< S!< s!< | Integer | same as the directives without "<" except L< l< L!< l!< | | little endian I!< i!< | | (available since Ruby 1.9.3) Q< q< Q!< q!< | | "S<" is the same as "v" J< j< J!< j!< | | "L<" is the same as "V" | | n | Integer | 16-bit unsigned, network (big-endian) byte order N | Integer | 32-bit unsigned, network (big-endian) byte order v | Integer | 16-bit unsigned, VAX (little-endian) byte order V | Integer | 32-bit unsigned, VAX (little-endian) byte order | | U | Integer | UTF-8 character w | Integer | BER-compressed integer Float | Array | Directive | Element | Meaning --------------------------------------------------------------------------- D d | Float | double-precision, native format F f | Float | single-precision, native format E | Float | double-precision, little-endian byte order e | Float | single-precision, little-endian byte order G | Float | double-precision, network (big-endian) byte order g | Float | single-precision, network (big-endian) byte order String | Array | Directive | Element | Meaning --------------------------------------------------------------------------- A | String | arbitrary binary string (space padded, count is width) a | String | arbitrary binary string (null padded, count is width) Z | String | same as ``a'', except that null is added with * B | String | bit string (MSB first) b | String | bit string (LSB first) H | String | hex string (high nibble first) h | String | hex string (low nibble first) u | String | UU-encoded string M | String | quoted printable, MIME encoding (see also RFC2045) | | (text mode but input must use LF and output LF) m | String | base64 encoded string (see RFC 2045) | | (if count is 0, no line feed are added, see RFC 4648) | | (count specifies input bytes between each LF, | | rounded down to nearest multiple of 3) P | String | pointer to a structure (fixed-length string) p | String | pointer to a null-terminated string Misc. | Array | Directive | Element | Meaning --------------------------------------------------------------------------- @ | --- | moves to absolute position X | --- | back up a byte x | --- | null byte
Returns a Hash
containing implementation-dependent counters inside the VM.
This hash includes information about method/constant cache serials:
{ :global_constant_state=>481, :class_serial=>9029 }
The contents of the hash are implementation specific and may be changed in the future.
This method is only expected to work on C Ruby.
The primary interface to this library. Use to setup delegation when defining your class.
class MyClass < DelegateClass(ClassToDelegateTo) # Step 1 def initialize super(obj_of_ClassToDelegateTo) # Step 2 end end
or:
MyClass = DelegateClass(ClassToDelegateTo) do # Step 1 def initialize super(obj_of_ClassToDelegateTo) # Step 2 end end
Here’s a sample of use from Tempfile
which is really a File
object with a few special rules about storage location and when the File
should be deleted. That makes for an almost textbook perfect example of how to use delegation.
class Tempfile < DelegateClass(File) # constant and class member data initialization... def initialize(basename, tmpdir=Dir::tmpdir) # build up file path/name in var tmpname... @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600) # ... super(@tmpfile) # below this point, all methods of File are supported... end # ... end
Calls the given block self
times with each integer in (0..self-1)
:
a = [] 5.times {|i| a.push(i) } # => 5 a # => [0, 1, 2, 3, 4]
With no block given, returns an Enumerator
.