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.
Array
Difference
Returns a new array that is a copy of the receiver, removing any items that also appear in any of the arrays given as arguments. The order is preserved from the original array.
It compares elements using their hash
and eql?
methods for efficiency.
[ 1, 1, 2, 2, 3, 3, 4, 5 ].difference([ 1, 2, 4 ]) #=> [ 3, 3, 5 ] [ 1, 'c', :s, 'yep' ].difference([ 1 ], [ 'a', 'c' ]) #=> [ :s, "yep" ]
If you need set-like behavior, see the library class Set
.
See also Array#-
.
Inserts the given values before the element with the given index
.
Negative indices count backwards from the end of the array, where -1
is the last element. If a negative index is used, the given values will be inserted after that element, so using an index of -1
will insert the values at the end of the array.
a = %w{ a b c d } a.insert(2, 99) #=> ["a", "b", 99, "c", "d"] a.insert(-2, 1, 2, 3) #=> ["a", "b", 99, "c", 1, 2, 3, "d"]
Returns a new array containing self
‘s elements in reverse order.
[ "a", "b", "c" ].reverse #=> ["c", "b", "a"] [ 1 ].reverse #=> [1]
Reverses self
in place.
a = [ "a", "b", "c" ] a.reverse! #=> ["c", "b", "a"] a #=> ["c", "b", "a"]
Returns a new array containing all elements of ary
for which the given block
returns a true value.
If no block is given, an Enumerator
is returned instead.
[1,2,3,4,5].select {|num| num.even? } #=> [2, 4] a = %w[ a b c d e f ] a.select {|v| v =~ /[aeiou]/ } #=> ["a", "e"]
See also Enumerable#select
.
Array#filter
is an alias for Array#select
.
Invokes the given block passing in successive elements from self
, deleting elements for which the block returns a false
value.
The array may not be changed instantly every time the block is called.
If changes were made, it will return self
, otherwise it returns nil
.
If no block is given, an Enumerator
is returned instead.
See also Array#keep_if
.
Array#filter!
is an alias for Array#select!
.
When invoked with a block, yield all permutations of length n
of the elements of the array, then return the array itself.
If n
is not specified, yield all permutations of all elements.
The implementation makes no guarantees about the order in which the permutations are yielded.
If no block is given, an Enumerator
is returned instead.
Examples:
a = [1, 2, 3] a.permutation.to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] a.permutation(1).to_a #=> [[1],[2],[3]] a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]] a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] a.permutation(0).to_a #=> [[]] # one permutation of length 0 a.permutation(4).to_a #=> [] # no permutations of length 4
provides a unified clone
operation, for REXML::XPathParser
to use across multiple Object+ types
Returns a Digest
subclass by name
in a thread-safe manner even when on-demand loading is involved.
require 'digest' Digest("MD5") # => Digest::MD5 Digest(:SHA256) # => Digest::SHA256 Digest(:Foo) # => LoadError: library not found for class Digest::Foo -- digest/foo
Allows for declaring a Gemfile inline in a ruby script, optionally installing any gems that aren’t already installed on the user’s system.
@note Every gem that is specified in this ‘Gemfile’ will be ‘require`d, as if
the user had manually called `Bundler.require`. To avoid a requested gem being automatically required, add the `:require => false` option to the `gem` dependency declaration.
@param install [Boolean] whether gems that aren’t already installed on the
user's system should be installed. Defaults to `false`.
@param gemfile [Proc] a block that is evaluated as a ‘Gemfile`.
@example Using an inline Gemfile
#!/usr/bin/env ruby require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'json', require: false gem 'nap', require: 'rest' gem 'cocoapods', '~> 0.34.1' end puts Pod::VERSION # => "0.34.4"
provides a unified clone
operation, for REXML::XPathParser
to use across multiple Object
types
Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. clone
copies the frozen (unless :freeze keyword argument is given with a false value) and tainted state of obj. See also the discussion under Object#dup
.
class Klass attr_accessor :str end s1 = Klass.new #=> #<Klass:0x401b3a38> s1.str = "Hello" #=> "Hello" s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello"> s2.str[1,4] = "i" #=> "i" s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">" s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
This method may have class-specific behavior. If so, that behavior will be documented under the #initialize_copy
method of the class.
Returns an array with both a numeric
and a big
represented as Bignum objects.
This is achieved by converting numeric
to a Bignum.
A TypeError
is raised if the numeric
is not a Fixnum or Bignum type.
(0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
provides a unified clone
operation, for REXML::XPathParser
to use across multiple Object
types
Returns the largest number less than or equal to int
with a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns self
when ndigits
is zero or positive.
1.floor #=> 1 1.floor(2) #=> 1 18.floor(-1) #=> 10 (-18).floor(-1) #=> -20
Returns the remainder after dividing int
by numeric
.
x.remainder(y)
means x-y*(x/y).truncate
.
5.remainder(3) #=> 2 -5.remainder(3) #=> -2 5.remainder(-3) #=> 2 -5.remainder(-3) #=> -2 5.remainder(1.5) #=> 0.5
See Numeric#divmod
.
Returns self.
Returns the numerator.
1 2 3+4i <- numerator - + -i -> ---- 2 3 6 <- denominator c = Complex('1/2+2/3i') #=> ((1/2)+(2/3)*i) n = c.numerator #=> (3+4i) d = c.denominator #=> 6 n / d #=> ((1/2)+(2/3)*i) Complex(Rational(n.real, d), Rational(n.imag, d)) #=> ((1/2)+(2/3)*i)
See denominator.
If numeric
is the same type as num
, returns an array [numeric, num]
. Otherwise, returns an array with both numeric
and num
represented as Float
objects.
This coercion mechanism is used by Ruby to handle mixed-type numeric operations: it is intended to find a compatible common type between the two operands of the operator.
1.coerce(2.5) #=> [2.5, 1.0] 1.2.coerce(3) #=> [3.0, 1.2] 1.coerce(2) #=> [2, 1]
Returns the receiver. freeze
cannot be false
.
Returns true
if num
has a zero value.