Returns true if other
is a subdomain.
Example:
domain = Resolv::DNS::Name.create("y.z") p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true p Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true p Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false p Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
Creates a string representation of self
, by calling inspect
on each element.
[ "a", "b", "c" ].to_s #=> "[\"a\", \"b\", \"c\"]"
Set
Intersection — Returns a new array containing unique elements common to self
and other_ary
s. Order is preserved from the original array.
It compares elements using their hash
and eql?
methods for efficiency.
[ 1, 1, 3, 5 ].intersection([ 3, 2, 1 ]) # => [ 1, 3 ] [ "a", "b", "z" ].intersection([ "a", "b", "c" ], [ "b" ]) # => [ "b" ] [ "a" ].intersection #=> [ "a" ]
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 the index of the first object in ary
such that the object is ==
to obj
.
If a block is given instead of an argument, returns the index of the first object for which the block returns true
. Returns nil
if no match is found.
See also Array#rindex
.
An Enumerator
is returned if neither a block nor argument is given.
a = [ "a", "b", "c" ] a.index("b") #=> 1 a.index("z") #=> nil a.index {|x| x == "b"} #=> 1
Returns the index of the last object in self
==
to obj
.
If a block is given instead of an argument, returns the index of the first object for which the block returns true
, starting from the last object.
Returns nil
if no match is found.
See also Array#index
.
If neither block nor argument is given, an Enumerator
is returned instead.
a = [ "a", "b", "b", "b", "c" ] a.rindex("b") #=> 3 a.rindex("z") #=> nil a.rindex {|x| x == "b"} #=> 3
Returns a string created by converting each element of the array to a string, separated by the given separator
. If the separator
is nil
, it uses current $,
. If both the separator
and $,
are nil
, it uses an empty string.
[ "a", "b", "c" ].join #=> "abc" [ "a", "b", "c" ].join("-") #=> "a-b-c"
For nested arrays, join is applied recursively:
[ "a", [1, 2, [:x, :y]], "b" ].join("-") #=> "a-1-2-x-y-b"
Invokes the given block once for each element of self
.
Creates a new array containing the values returned by the block.
See also Enumerable#collect
.
If no block is given, an Enumerator
is returned instead.
a = [ "a", "b", "c", "d" ] a.collect {|x| x + "!"} #=> ["a!", "b!", "c!", "d!"] a.map.with_index {|x, i| x * i} #=> ["", "b", "cc", "ddd"] a #=> ["a", "b", "c", "d"]
Invokes the given block once for each element of self
, replacing the element with the value returned by the block.
See also Enumerable#collect
.
If no block is given, an Enumerator
is returned instead.
a = [ "a", "b", "c", "d" ] a.map! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] a.collect!.with_index {|x, i| x[0...i] } a #=> ["", "b", "c!", "d!"]
Returns true
if the given object
is present in self
(that is, if any element ==
object
), otherwise returns false
.
a = [ "a", "b", "c" ] a.include?("b") #=> true a.include?("z") #=> false
When invoked with a block, yields all combinations of length n
of elements from the array and then returns the array itself.
The implementation makes no guarantees about the order in which the combinations are yielded.
If no block is given, an Enumerator
is returned instead.
Examples:
a = [1, 2, 3, 4] a.combination(1).to_a #=> [[1],[2],[3],[4]] a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]] a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]] a.combination(4).to_a #=> [[1,2,3,4]] a.combination(0).to_a #=> [[]] # one combination of length 0 a.combination(5).to_a #=> [] # no combinations of length 5
Builds a command line string from an argument list array
joining all elements escaped for the Bourne shell and separated by a space.
See Shellwords.shelljoin
for details.
Returns object. This method is deprecated and will be removed in Ruby 3.2.
Returns false. This method is deprecated and will be removed in Ruby 3.2.
Returns object. This method is deprecated and will be removed in Ruby 3.2.
Returns a string containing a human-readable representation of obj. The default inspect
shows the object’s class name, an encoding of the object id, and a list of the instance variables and their values (by calling inspect
on each of them). User defined classes should override this method to provide a better representation of obj. When overriding this method, it should return a string whose encoding is compatible with the default external encoding.
[ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "2008-03-08 19:43:39 +0900" class Foo end Foo.new.inspect #=> "#<Foo:0x0300c868>" class Bar def initialize @bar = 1 end end Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
Since int
is already an Integer
, this always returns true
.
Returns the absolute value of int
.
(-12345).abs #=> 12345 -12345.abs #=> 12345 12345.abs #=> 12345
Integer#magnitude
is an alias for Integer#abs
.
Returns a string containing the place-value representation of int
with radix base
(between 2 and 36).
12345.to_s #=> "12345" 12345.to_s(2) #=> "11000000111001" 12345.to_s(8) #=> "30071" 12345.to_s(10) #=> "12345" 12345.to_s(16) #=> "3039" 12345.to_s(36) #=> "9ix" 78546939656932.to_s(36) #=> "rubyrules"
Returns the absolute part of its polar form.
Complex(-1).abs #=> 1 Complex(3.0, -4.0).abs #=> 5.0
Returns the value as a string for inspection.
Complex(2).inspect #=> "(2+0i)" Complex('-8/6').inspect #=> "((-4/3)+0i)" Complex('1/2i').inspect #=> "(0+(1/2)*i)" Complex(0, Float::INFINITY).inspect #=> "(0+Infinity*i)" Complex(Float::NAN, Float::NAN).inspect #=> "(NaN+NaN*i)"
Returns true
if cmp
‘s real and imaginary parts are both finite numbers, otherwise returns false
.