The version of Ruby required by this gem. The ruby version can be specified to the patch-level:
$ ruby -v -e 'p Gem.ruby_version' ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0] #<Gem::Version "2.0.0.247">
Prereleases can also be specified.
Usage:
# This gem will work with 1.8.6 or greater... spec.required_ruby_version = '>= 1.8.6' # Only with final releases of major version 2 where minor version is at least 3 spec.required_ruby_version = '~> 2.3' # Only prereleases or final releases after 2.6.0.preview2 spec.required_ruby_version = '> 2.6.0.preview2' # This gem will work with 2.3.0 or greater, including major version 3, but lesser than 4.0.0 spec.required_ruby_version = '>= 2.3', '< 4'
The RubyGems version required by this gem
Returns the source encoding name as a string.
Returns the destination encoding name as a string.
Returns the source encoding name as a string.
Returns the destination encoding name as a string.
The line number in the source code where this AST’s text began.
The column number in the source code where this AST’s text began.
Obsolete: use subtype
instead. Calling this will generate a warning message to stderr
, then return the value of subtype
.
Obsolete: use subtype
instead. Calling this will generate a warning message to stderr
, then return the value of subtype
.
Obsolete: use subtype
instead. Calling this will generate a warning message to stderr
, then return the value of subtype
.
Obsolete: use subtype
instead. Calling this will generate a warning message to stderr
, then return the value of subtype
.
Verifies each certificate in chain
has signed the following certificate and is valid for the given time
.
Returns the element at offset index
.
With the single Integer argument index
, returns the element at offset index
:
a = [:foo, 'bar', 2] a.fetch(1) # => "bar"
If index
is negative, counts from the end of the array:
a = [:foo, 'bar', 2] a.fetch(-1) # => 2 a.fetch(-2) # => "bar"
With arguments index
and default_value
, returns the element at offset index
if index is in range, otherwise returns default_value
:
a = [:foo, 'bar', 2] a.fetch(1, nil) # => "bar"
With argument index
and a block, returns the element at offset index
if index is in range (and the block is not called); otherwise calls the block with index and returns its return value:
a = [:foo, 'bar', 2] a.fetch(1) {|index| raise 'Cannot happen' } # => "bar" a.fetch(50) {|index| "Value for #{index}" } # => "Value for 50"
Iterates over array elements.
When a block given, passes each successive array element to the block; returns self
:
a = [:foo, 'bar', 2] a.each {|element| puts "#{element.class} #{element}" }
Output:
Symbol foo String bar Integer 2
Allows the array to be modified during iteration:
a = [:foo, 'bar', 2] a.each {|element| puts element; a.clear if element.to_s.start_with?('b') }
Output:
foo bar
When no block given, returns a new Enumerator:
a = [:foo, 'bar', 2] e = a.each e # => #<Enumerator: [:foo, "bar", 2]:each> a1 = e.each {|element| puts "#{element.class} #{element}" }
Output:
Symbol foo String bar Integer 2
Related: each_index
, reverse_each
.
Returns an element from self
selected by a binary search. self
should be sorted, but this is not checked.
By using binary search, finds a value from this array which meets the given condition in O(log n)
where n
is the size of the array.
There are two search modes:
Find-minimum mode: the block should return true
or false
.
Find-any mode: the block should return a numeric value.
The block should not mix the modes by and sometimes returning true
or false
and sometimes returning a numeric value, but this is not checked.
Find-Minimum Mode
In find-minimum mode, the block always returns true
or false
. The further requirement (though not checked) is that there are no indexes i
and j
such that:
0 <= i < j <= self.size
.
The block returns true
for self[i]
and false
for self[j]
.
In find-minimum mode, method bsearch returns the first element for which the block returns true.
Examples:
a = [0, 4, 7, 10, 12] a.bsearch {|x| x >= 4 } # => 4 a.bsearch {|x| x >= 6 } # => 7 a.bsearch {|x| x >= -1 } # => 0 a.bsearch {|x| x >= 100 } # => nil
Less formally: the block is such that all false
-evaluating elements precede all true
-evaluating elements.
These make sense as blocks in find-minimum mode:
a = [0, 4, 7, 10, 12] a.map {|x| x >= 4 } # => [false, true, true, true, true] a.map {|x| x >= 6 } # => [false, false, true, true, true] a.map {|x| x >= -1 } # => [true, true, true, true, true] a.map {|x| x >= 100 } # => [false, false, false, false, false]
This would not make sense:
a = [0, 4, 7, 10, 12] a.map {|x| x == 7 } # => [false, false, true, false, false]
Find-Any Mode
In find-any mode, the block always returns a numeric value. The further requirement (though not checked) is that there are no indexes i
and j
such that:
0 <= i < j <= self.size
.
The block returns a negative value for self[i]
and a positive value for self[j]
.
The block returns a negative value for self[i]
and zero self[j]
.
The block returns zero for self[i]
and a positive value for self[j]
.
In find-any mode, method bsearch returns some element for which the block returns zero, or nil
if no such element is found.
Examples:
a = [0, 4, 7, 10, 12] a.bsearch {|element| 7 <=> element } # => 7 a.bsearch {|element| -1 <=> element } # => nil a.bsearch {|element| 5 <=> element } # => nil a.bsearch {|element| 15 <=> element } # => nil
Less formally: the block is such that:
All positive-evaluating elements precede all zero-evaluating elements.
All positive-evaluating elements precede all negative-evaluating elements.
All zero-evaluating elements precede all negative-evaluating elements.
These make sense as blocks in find-any mode:
a = [0, 4, 7, 10, 12] a.map {|element| 7 <=> element } # => [1, 1, 0, -1, -1] a.map {|element| -1 <=> element } # => [-1, -1, -1, -1, -1] a.map {|element| 5 <=> element } # => [1, 1, -1, -1, -1] a.map {|element| 15 <=> element } # => [1, 1, 1, 1, 1]
This would not make sense:
a = [0, 4, 7, 10, 12] a.map {|element| element <=> 7 } # => [-1, -1, 0, 1, 1]
Returns an enumerator if no block given:
a = [0, 4, 7, 10, 12] a.bsearch # => #<Enumerator: [0, 4, 7, 10, 12]:bsearch>
Returns a string containing the character represented by the int
‘s value according to encoding
.
65.chr #=> "A" 230.chr #=> "\xE6" 255.chr(Encoding::UTF_8) #=> "\u00FF"