Whether the critical flag is set on this property.
Is this tar entry a directory?
Returns the count of elements in self
:
[0, 1, 2].length # => 3 [].length # => 0
Related: see Methods for Querying.
Removes zero or more elements from self
.
With no block given, removes from self
each element ele
such that ele == object
; returns the last removed element:
a = [0, 1, 2, 2.0] a.delete(2) # => 2.0 a # => [0, 1]
Returns nil
if no elements removed:
a.delete(2) # => nil
With a block given, removes from self
each element ele
such that ele == object
.
If any such elements are found, ignores the block and returns the last removed element:
a = [0, 1, 2, 2.0] a.delete(2) {|element| fail 'Cannot happen' } # => 2.0 a # => [0, 1]
If no such element is found, returns the block’s return value:
a.delete(2) {|element| "Element #{element} not found." } # => "Element 2 not found."
Related: see Methods for Deleting.
Removes all elements from self
; returns self
:
a = [:foo, 'bar', 2] a.clear # => []
Related: see Methods for Deleting.
With a block given, may call the block, depending on the value of argument count
; count
must be an integer-convertible object, or nil
.
When count
is positive, calls the block with each element, then does so repeatedly, until it has done so count
times; returns nil
:
output = [] [0, 1].cycle(2) {|element| output.push(element) } # => nil output # => [0, 1, 0, 1]
When count
is zero or negative, does not call the block:
[0, 1].cycle(0) {|element| fail 'Cannot happen' } # => nil [0, 1].cycle(-1) {|element| fail 'Cannot happen' } # => nil
When count
is nil
, cycles forever:
# Prints 0 and 1 forever. [0, 1].cycle {|element| puts element } [0, 1].cycle(nil) {|element| puts element }
With no block given, returns a new Enumerator
.
Related: see Methods for Iterating.
Shuffles all elements in self
into a random order, as selected by the object given by the keyword argument random
. Returns self
:
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] a.shuffle! # => [5, 3, 8, 7, 6, 1, 9, 4, 2, 0] a.shuffle! # => [9, 4, 0, 6, 2, 8, 1, 5, 3, 7]
Duplicate elements are included:
a = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] a.shuffle! # => [1, 0, 0, 1, 1, 0, 1, 0, 0, 1] a.shuffle! # => [0, 1, 0, 1, 1, 0, 1, 0, 1, 0]
The object given with the keyword argument random
is used as the random number generator.
Related: see Methods for Assigning.
Returns a new array containing all elements from self
in a random order, as selected by the object given by the keyword argument random
:
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] a.shuffle # => [0, 8, 1, 9, 6, 3, 4, 7, 2, 5] a.shuffle # => [8, 9, 0, 5, 1, 2, 6, 4, 7, 3]
Duplicate elements are included:
a = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] a.shuffle # => [1, 0, 1, 1, 0, 0, 1, 0, 0, 1] a.shuffle # => [1, 1, 0, 0, 0, 1, 1, 0, 0, 1]
The object given with the keyword argument random
is used as the random number generator.
Related: see Methods for Fetching.
Returns random elements from self
, as selected by the object given by the keyword argument random
.
With no argument count
given, returns one random element from self
:
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] a.sample # => 3 a.sample # => 8
Returns nil
if self
is empty:
[].sample # => nil
With a non-negative numeric argument count
given, returns a new array containing count
random elements from self
:
a.sample(3) # => [8, 9, 2] a.sample(6) # => [9, 6, 0, 3, 1, 4]
The order of the result array is unrelated to the order of self
.
Returns a new empty Array
if self
is empty:
[].sample(4) # => []
May return duplicates in self
:
a = [1, 1, 1, 2, 2, 3] a.sample(a.size) # => [1, 1, 3, 2, 1, 2]
Returns no more than a.size
elements (because no new duplicates are introduced):
a.sample(50) # => [6, 4, 1, 8, 5, 9, 0, 2, 3, 7]
The object given with the keyword argument random
is 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]
Related: see Methods for Fetching.
Returns true
if self
is an odd number, false
otherwise.
Returns the argument (angle) for self
in radians; see polar coordinates:
Complex.polar(3, Math::PI/2).arg # => 1.57079632679489660
If self
was created with rectangular coordinates, the returned value is computed, and may be inexact:
Complex.polar(1, 1.0/3).arg # => 0.33333333333333326
Returns zero if self
is positive, Math::PI otherwise.
Escapes str
so that it can be safely used in a Bourne shell command line.
See Shellwords.shellescape
for details.
Returns the count of characters (not bytes) in self
:
'foo'.length # => 3 'тест'.length # => 4 'こんにちは'.length # => 5
Contrast with String#bytesize
:
'foo'.bytesize # => 3 'тест'.bytesize # => 8 'こんにちは'.bytesize # => 15
Returns a printable version of self
, enclosed in double-quotes, with special characters escaped, and with non-printing characters replaced by hexadecimal notation:
"hello \n ''".dump # => "\"hello \\n ''\"" "\f\x00\xff\\\"".dump # => "\"\\f\\x00\\xFF\\\\\\\"\""
Related: String#undump
(inverse of String#dump
).
Returns an array of the codepoints in self
; each codepoint is the integer value for a character:
'hello'.codepoints # => [104, 101, 108, 108, 111] 'тест'.codepoints # => [1090, 1077, 1089, 1090] 'こんにちは'.codepoints # => [12371, 12435, 12395, 12385, 12399]
Returns a copy of self
with characters specified by selectors
removed (see Multiple Character Selectors):
"hello".delete "l","lo" #=> "heo" "hello".delete "lo" #=> "he" "hello".delete "aeiou", "^e" #=> "hell" "hello".delete "ej-m" #=> "ho"
Like String#delete
, but modifies self
in place. Returns self
if any changes were made, nil
otherwise.
Returns a frozen, possibly pre-existing copy of the string.
The returned String
will be deduplicated as long as it does not have any instance variables set on it and is not a String
subclass.
Note that -string
variant is more convenient for defining constants:
FILENAME = -'config/database.yml'
while dedup
is better suitable for using the method in chains of calculations:
@url_list.concat(urls.map(&:dedup))