Path of activations from the current
list.
Return a String
indicating who caused this request to be added (only valid for implicit requests)
Returns true
if this gem is installable for the current platform.
Returns true
if this gem is installable for the current platform.
Returns true if this specification is installable on this platform.
When self
is an instance of Array, returns self
.
Otherwise, returns a new array containing the elements of self
:
class MyArray < Array; end my_a = MyArray.new(['foo', 'bar', 'two']) a = my_a.to_a a # => ["foo", "bar", "two"] a.class # => Array # Not MyArray.
Related: see Methods for Converting.
Returns a new hash formed from self
.
With no block given, each element of self
must be a 2-element sub-array; forms each sub-array into a key-value pair in the new hash:
a = [['foo', 'zero'], ['bar', 'one'], ['baz', 'two']] a.to_h # => {"foo"=>"zero", "bar"=>"one", "baz"=>"two"} [].to_h # => {}
With a block given, the block must return a 2-element array; calls the block with each element of self
; forms each returned array into a key-value pair in the returned hash:
a = ['foo', :bar, 1, [2, 3], {baz: 4}] a.to_h {|element| [element, element.class] } # => {"foo"=>String, :bar=>Symbol, 1=>Integer, [2, 3]=>Array, {:baz=>4}=>Hash}
Related: see Methods for Converting.
Returns a new array containing only those elements from self
that are not found in any of the given other_arrays
; items are compared using eql?
; order from self
is preserved:
[0, 1, 1, 2, 1, 1, 3, 1, 1].difference([1]) # => [0, 2, 3] [0, 1, 2, 3].difference([3, 0], [1, 3]) # => [2] [0, 1, 2].difference([4]) # => [0, 1, 2] [0, 1, 2].difference # => [0, 1, 2]
Returns a copy of self
if no arguments are given.
Related: Array#-
; see also Methods for Combining.
Returns a new array containing the elements of self
in reverse order:
[0, 1, 2].reverse # => [2, 1, 0]
Related: see Methods for Combining.
Reverses the order of the elements of self
; returns self
:
a = [0, 1, 2] a.reverse! # => [2, 1, 0] a # => [2, 1, 0]
Related: see Methods for Assigning.
Returns a new array containing the elements of self
, sorted.
With no block given, compares elements using operator <=>
(see Object#<=>
):
[0, 2, 3, 1].sort # => [0, 1, 2, 3]
With a block given, calls the block with each combination of pairs of elements from self
; for each pair a
and b
, the block should return a numeric:
Negative when b
is to follow a
.
Zero when a
and b
are equivalent.
Positive when a
is to follow b
.
Example:
a = [3, 2, 0, 1] a.sort {|a, b| a <=> b } # => [0, 1, 2, 3] a.sort {|a, b| b <=> a } # => [3, 2, 1, 0]
When the block returns zero, the order for a
and b
is indeterminate, and may be unstable.
See an example in Numeric#nonzero?
for the idiom to sort more complex structure.
Related: see Methods for Fetching.
Like Array#sort
, but returns self
with its elements sorted in place.
Related: see Methods for Assigning.
With a block given, returns a new array whose elements are all those from self
for which the block returns false
or nil
:
a = [:foo, 'bar', 2, 'bat'] a1 = a.reject {|element| element.to_s.start_with?('b') } a1 # => [:foo, 2]
With no block given, returns a new Enumerator
.
Related: Methods for Fetching.
With a block given, calls the block with each element of self
; removes each element for which the block returns a truthy value.
Returns self
if any elements removed:
a = [:foo, 'bar', 2, 'bat'] a.reject! {|element| element.to_s.start_with?('b') } # => [:foo, 2]
Returns nil
if no elements removed.
With no block given, returns a new Enumerator
.
Related: see Methods for Deleting.
Replaces the elements of self
with the elements of other_array
, which must be an array-convertible object; returns self
:
a = ['a', 'b', 'c'] # => ["a", "b", "c"] a.replace(['d', 'e']) # => ["d", "e"]
Related: see Methods for Assigning.
Freezes self
(if not already frozen); returns self
:
a = [] a.frozen? # => false a.freeze a.frozen? # => true
No further changes may be made to self
; raises FrozenError
if a change is attempted.
Related: Kernel#frozen?
.
Returns the new string formed by calling method inspect
on each array element:
a = [:foo, 'bar', 2] a.inspect # => "[:foo, \"bar\", 2]"
Related: see Methods for Converting.
Prepends the given objects
to self
:
a = [:foo, 'bar', 2] a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]
Related: Array#shift
; see also Methods for Assigning.
Returns elements from self
, or nil
; does not modify self
.
With no argument given, returns the first element (if available):
a = [:foo, 'bar', 2] a.first # => :foo a # => [:foo, "bar", 2]
If self
is empty, returns nil
.
[].first # => nil
With a non-negative integer argument count
given, returns the first count
elements (as available) in a new array:
a.first(0) # => [] a.first(2) # => [:foo, "bar"] a.first(50) # => [:foo, "bar", 2]
Related: see Methods for Querying.