Class: RubyJS.Array

Defined in: lib/corelib/array.coffee
Inherits: RubyJS.Object

Overview

TODO: No proper support for handling recursive arrays. (e.g. a = [], a.push(a)). Look for ArraySpecs.recursive_array in the specs.
TODO: The methods #taint, #trust, #freeze do nothing

Array wraps a javascript array.

Class Method Summary

Instance Method Summary

Inherited Method Summary

Methods inherited from RubyJS.Object

.include, .__add_default_aliases__, #send, #respond_to, #to_enum, #tap

Class Method Details

+ (void) new(args...)

Returns a new array. In the first form, the new array is empty. In the second it is created with size copies of obj (that is, size references to the same obj). The third form creates a copy of the array passed as a parameter (the array is generated by calling #to_ary on the parameter). In the last form, an array of the given size is created. Each element in this array is calculated by passing the element’s index to the given block and storing the return value.

Examples:

  R.Array.new()                  # => []
  R.Array.new(2)                 # => [null, null]
  R.Array.new(3, "A")            # => ['A','A','A']
  # only one copy of the object is created
  a = R.Array.new(2, R('a') )   # => ['a', 'a']
  a[0].capitalize_bang()
  a                             # => ['A', 'A']
  # here multiple copies are created
  a = R.Array.new(2, -> R('a'))
  squares = R.Array.new(5, (i) -> i.multiply(i)
  copy = R.Array.new(squares)

+ (void) try_convert(obj)

TODO: Does currently not check if value from to_ary() is an Array

Try to convert obj into an array, using to_ary method. Returns converted array or nil if obj cannot be converted for any reason. This method can be used to check if an argument is an array.

Examples:

  R.Array.try_convert([1])      # => [1]
  R.Array.try_convert(R([1]))   # => [1]
  R.Array.try_convert("1")      # => null

Constructor Details

- (void) constructor(__native__ = [], recursive)

Creates a new R.Array with a clone of the given array.

Instance Method Details

- (Boolean) equals()

Alias for {#==} - Two arrays are equal if they contain the same number of elements and if each element is equal to (according to {R.Object#==}) the corresponding element in the other array. @alias #==

Examples:

 R(["a", "c"]   ).equals(["a", "c", 7])     #=> false
 R(["a", "c", 7]).equals(["a", "c", 7])     #=> true
 R(["a", "c", 7]).equals(["a", "d", "f"])   #=> false
 # #equals is an alias to #==
 R(["a", "c"]   )['=='](["a", "c", 7])     #=> false

Returns:

  • Boolean

- (R.Array) append(obj)

Alias for {#<<} - Pushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together.

Examples:

 R([ 1, 2 ]).append("c").append("d").append([3, 4])
 #=> [ 1, 2, "c", "d", [ 3, 4 ] ]

Parameters:

  • obj (Object)

Returns:

  • R.Array

- (R.Array) intersection(other)

TODO: Slow implementation, slight deviation Ruby implementation of equality check

Alias for {#&} - Returns a new array containing elements common to the two arrays, with no duplicates. @alias #&

Examples:

R([ 1, 1, 3, 5 ]).intersection [ 1, 2, 3 ]
#=> [ 1, 3 ]

Parameters:

  • other (Array)

Returns:

  • R.Array

- (R.Array) cmp(other)

Alias for {#<=>} - Returns an integer (-1, 0, or +1) if this array is less than, equal to, or greater than other_ary. Each object in each array is compared (using <=>). If any value isn’t equal, then that inequality is the return value. If all the values found are equal, then the return is based on a comparison of the array lengths. Thus, two arrays are “equal” according to {R.Array#<=>} if and only if they have the same length and the value of each element is equal to the value of the corresponding element in the other array.

Examples:

R([ "a", "a", "c" ]   )['<=>'] [ "a", "b", "c" ]   #=> -1
R([ 1, 2, 3, 4, 5, 6 ])['<=>'] [ 1, 2 ]            #=> +1

Parameters:

  • other (Array)

Returns:

  • R.Array

- (?) valueOf()

Returns native array.

Returns:

  • (?) — Array

- (?) to_native(recursive = false)

Returns native array.

Parameters:

  • recursive (boolean) if set to true array and its elements are unboxed

Returns:

  • (?) — Array

- (void) to_native_clone()

- (void) '=='(other)

- (void) '<<'(obj)

- (void) '&'(other)

'-instance'> - (void) '<=>'(other)

- (Object) at(index)

Returns the element at index. A negative index counts from the end of self. Returns nil if the index is out of range. See also Array#[].

Examples:

  a = R([ "a", "b", "c", "d", "e" ])
  a.at(0)     #=> "a"
  a.at(-1)    #=> "e"

Returns:

  • Object

- (R.Array) clear()

Removes all elements from self.

Examples:

  a = R([ "a", "b", "c", "d", "e" ])
  a.clear()    #=> [ ]

Returns:

  • R.Array

- (void) clone()

TODO: does not copy the singleton class of the copied object

- (?) collect_bang(block)

Note: some edge-cases not handled when breaking out from block.

Invokes the block once for each element of self, replacing the element with the value returned by block. See also Enumerable#collect.

If no block is given, an enumerator is returned instead.

@alias #map_bang

Examples:

  a = R([ "a", "b", "c", "d" ])
  a.collect_bang (x) -> x+"!"
  a
  #=>  [ "a!", "b!", "c!", "d!" ]

Returns:

  • (?) — self

- (?) combination(args...)

When invoked with a block, yields all combinations of length n of elements from ary and then returns ary 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 = R([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
  R([1, 2, 3, 4]).combination(3).to_a()

Returns:

  • (?) — R.Array

- (R.Array) compact()

Returns a copy of self with all nil elements removed.

Examples:

  R([ "a", nil, "b", nil, "c", nil ]).compact()
  #=> [ "a", "b", "c" ]

Returns:

  • R.Array

- (?) compact_bang()

Removes nil elements from the array. Returns nil if no changes were made, otherwise returns ary.

Examples:


  R([ "a", nil, "b", nil, "c" ]).compact_bang()
  # => [ "a", "b", "c" ]
  R([ "a", "b", "c" ]).compact_bang()
  # => null

Returns:

  • (?) — self or null if nothing changed

- (?) concat(other)

Appends the elements of other_ary to self.

Examples:

  R([ "a", "b" ]).concat( ["c", "d"] )
  #=> [ "a", "b", "c", "d" ]

Returns:

  • (?) — R.Array

- (void) delete(args...)

Deletes items from self that are equal to obj. If any items are found, returns obj. If the item is not found, returns nil. If the optional code block is given, returns the result of block if the item is not found. (To remove nil elements and get an informative return value, use compact!)

Examples:

  a = R([ "a", "b", "b", "b", "c" ])
  a.delete("b")                   #=> "b"
  a                               #=> ["a", "c"]
  a.delete("z")                   #=> nil
  a.delete("z", -> 'not found')   #=> "not found"

- (?) delete_at(idx)

Deletes the element at the specified index, returning that element, or nil if the index is out of range. See also Array#slice!.

Examples:

 a = R.w('ant bat cat dog')
 a.delete_at(2)    #=> "cat"
 a                 #=> ["ant", "bat", "dog"]
 a.delete_at(99)   #=> null

Returns:

  • (?) — obj or null

- (R.Array, R.Enumerator) delete_if(block)

Deletes every element of self for which block evaluates to true. The array is changed instantly every time the block is called and not after the iteration is over. See also Array#reject!

If no block is given, an enumerator is returned instead.

Examples:

  a = R([ "a", "b", "c" ])
  a.delete_if (x) -> x >= "b"
  #=> ["a"]

Returns:

  • (R.Array, R.Enumerator) — when no block

- (void) dup()

- (void) eql(other)

TODO: should not call #to_ary on its argument, but it does through boxing, Array.try_convert

- (void) each_index(block)

Same as Array#each, but passes the index of the element instead of the element itself.

If no block is given, an enumerator is returned instead.

Examples:

  a = R([ "a", "b", "c" ])
  a.each_index (x) -> R.puts "#{x} -- "
  # out: 0 -- 1 -- 2 --

- (void) each(block)

Calls block once for each element in self, passing that element as a parameter.

If no block is given, an enumerator is returned instead.

@alias #each

Examples:

  a = R([ "a", "b", "c" ])
  a.each (x) -> R.puts "#{x} -- "
  # out: a -- b -- c --

- (void) get(a, b)

Alias for R.Array#[] R.Array#slice

Element Reference—Returns the element at index, or returns a subarray starting at start and continuing for length elements, or returns a subarray specified by range. Negative indices count backward from the end of the array (-1 is the last element). Returns nil if the index (or starting index) are out of range.

Examples:

  a = R([ "a", "b", "c", "d", "e" ])
  a.get(2) +  a.get(0) + a.get(1)    #=> "cab"
  a.get(6)                   #=> nil
  a.get(1, 2)                #=> [ "b", "c" ]
  a.get(R.rng(1,3))          #=> [ "b", "c", "d" ]
  a.get(R.rng(4,7))          #=> [ "e" ]
  a.get(R.rng(6,10))         #=> nil
  a.get(-3, 3)               #=> [ "c", "d", "e" ]
  # special cases
  a.get(5)                   #=> nil
  a.get(5, 1)                #=> []
  a.get(R.rng(5,10))         #=> []

- (void) set(idx, obj)

TODO: IMPLEMENT remaining arguments!!

- (void) empty()

Returns true if self contains no elements.

- (void) fetch(args...)

Tries to return the element at position index. If the index lies outside the array, the first form throws an IndexError exception, the second form returns default, and the third form returns the value of invoking the block, passing in the index. Negative values of index count from the end of the array.

Examples:

  a = R([ 11, 22, 33, 44 ])
  a.fetch(1)               #=> 22
  a.fetch(-1)              #=> 44
  a.fetch(4, 'cat')        #=> "cat"
  a.fetch(4, (i) -> i*i))  #=> 16

- (void) fill(args...)

TODO: implement fill(range, ...)

Fills array with obj or block.

fill(obj) → ary
fill(obj, start [, length]) → ary
fill(obj, range ) → ary
fill (index) -> block  → ary
fill(start [, length],  (index) -> block  → ary
# not yet implemented:
fill(range, (index) -> block ) → ary

The first three forms set the selected elements of self (which may be the entire array) to obj. A start of nil is equivalent to zero. A length of nil is equivalent to self.length. The last three forms fill the array with the value of the block. The block is passed the absolute index of each element to be filled. Negative values of start count from the end of the array.

Examples:

  a = R([ "a", "b", "c", "d" ])
  a.fill("x")               #=> ["x", "x", "x", "x"]
  a.fill("z", 2, 2)         #=> ["x", "x", "z", "z"]
  # a.fill("y", 0..1)         #=> ["y", "y", "z", "z"]
  a.fill (i) -> i*i         #=> [0, 1, 4, 9]
  a.fill(-2) (i) -> i*i*i   #=> [0, 1, 8, 27]

- (void) flatten(recursion = -1)

TODO: fails for [undefined, null]
TODO: do not typecast elements!

Returns a new array that is a one-dimensional flattening of this array (recursively). That is, for every element that is an array, extract its elements into the new array. If the optional level argument determines the level of recursion to flatten.

TODO: IMPORTANT!

Examples:

  s = R([ 1, 2, 3 ])           #=> [1, 2, 3]
  t = R([ 4, 5, 6, [7, 8] ])   #=> [4, 5, 6, [7, 8]]
  a = R([ s, t, 9, 10 ])       #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
  a.flatten()                  #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  a = R([ 1, 2, [3, [4, 5] ] ])
  a.flatten(1)                 #=> [1, 2, 3, [4, 5]]

- (void) insert(idx, items...)

Inserts the given values before the element with the given index (which may be negative).

Examples:

  a = R.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"]

- (void) inspect()

Creates a string representation of self.

Also aliased as: {#to_s}

Examples:

  R([1,2]).inspect()     # => '[1, 2]'

- (void) join(separator)

TODO: Does not ducktype via #to_str, #to_ary, #to_s or throw error

Returns a string created by converting each element of the array to a string, separated by sep.

Examples:

  R([ "a", "b", "c"]).join()      # => "abc"
  R([ "a", "b", "c"]).join(null)  # => "abc"
  R([ "a", "b", "c"]).join("-")   # => "a-b-c"
  # joins nested arrays
  R([1,[2,[3,4]]]).join('.')      # => '1.2.3.4'
  # Default separator R['$,'] (in ruby: $,)
  R['$,']                        # => null
  R([ "a", "b", "c"]).join()      # => "abc"
  R['$,'] = '|'                  # => '|'
  R([ "a", "b", "c"]).join()      # => "a|b|c"

- (void) keep_if(block)

Deletes every element of self for which block evaluates to false. See also Array#select!

If no block is given, an enumerator is returned instead.

Examples:

  a = R([1,2,3,4])
  a.keep_if (v) -> i < 3   # => [1,2,3]
  a.keep_if  -> true       # => a # returns self if not changed

- (void) minus(other)

TODO: recursive arrays not tested
Note: minus checks for identity using other.include(el), which differs slightly from the reference which uses #hash and #eql?

Array Difference - Returns a new array that is a copy of the original array, removing any items that also appear in other_ary. (If you need set- like behavior, see the library class Set.)

Examples:

  R([ 1, 1, 2, 2, 3, 3, 4, 5 ]) - [ 1, 2, 4 ]  #=>  [ 3, 3, 5 ]

- (void) multiply(multiplier)

Repetition—With a String argument, equivalent to self.join(str). Otherwise, returns a new array built by concatenating the int copies of self.

Examples:

  R([ 1, 2, 3 ]).multiply 3    # => [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
  R([ 1, 2, 3 ]).multiply ","  # => "1,2,3"

- (void) last(n)

Returns the last element(s) of self. If the array is empty, the first form returns nil.

Examples:

  a = R([ "w", "x", "y", "z" ])
  a.last()     #=> "z"
  a.last(2)    #=> ["y", "z"]

- (void) plus(other)

Note: recursive arrays untested.

Concatenation—Returns a new array built by concatenating the two arrays together to produce a third array.

Examples:

  R([ 1, 2, 3 ]).plus [ 3, 4 ]     #=> [ 1, 2, 3, 3, 4 ]
  R([ 1, 2, 3 ])['+']([ 3, 4 ])    #=> [ 1, 2, 3, 3, 4 ]

- (void) pop(many)

TODO: check for recursive arrays

Removes the last element from self and returns it, or nil if the array is empty.

If a number n is given, returns an array of the last n elements (or less) just like array.slice!(-n, n) does.

Examples:

  a = R([ "a", "b", "c", "d" ])
  a.pop()     # => "d"
  a.pop(2)    # => ["b", "c"]
  a           # => ["a"]

- (void) product(args...)

TODO: does not check if the result size will fit in an Array.

Returns an array of all combinations of elements from all arrays. The length of the returned array is the product of the length of self and the argument arrays. If given a block, product will yield all combinations and return self instead.

Examples:

  R( [1,2,3] ).product([4,5])       #=> [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]
  R( [1,2]   ).product([1,2])       #=> [[1,1],[1,2],[2,1],[2,2]]
  R( [1,2]   ).product([3,4],[5,6]) #=> [[1,3,5],[1,3,6],[1,4,5],[1,4,6],
                                    #     [2,3,5],[2,3,6],[2,4,5],[2,4,6]]
  R( [1,2] ).product()              #=> [[1],[2]]
  R( [1,2] ).product([])            #=> []

- (void) push()

Append—Pushes the given object(s) on to the end of this array. This expression returns the array itself, so several appends may be chained together.

Examples:

  a = R([ "a", "b", "c" ])
  a.push("d", "e", "f")
  #=> ["a", "b", "c", "d", "e", "f"]

- (void) rassoc(obj)

Searches through the array whose elements are also arrays. Compares obj with the second element of each contained array using ==. Returns the first contained array that matches. See also Array#assoc.

Examples:

  a = R([ [ 1, "one"], [2, "two"], [3, "three"], ["ii", "two"] ])
  a.rassoc("two")    #=> [2, "two"]
  a.rassoc("four")   #=> nil

- (void) rindex(other)

Note: does not check if array has changed.

Returns the index of the last object in self == to obj. If a block is given instead of an argument, returns index of first object for which block is 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.

Examples:

  a = R([ "a", "b", "b", "b", "c" ])
  a.rindex("b")             # => 3
  a.rindex("z")             # => nil
  a.rindex (x) -> x == "b"  # => 3

- (void) sample(n, range = void 0)

Choose a random element or n random elements from the array. The elements are chosen by using random and unique indices into the array in order to ensure that an element doesn’t repeat itself unless the array already contained duplicate elements. If the array is empty the first form returns nil and the second form returns an empty array.

If rng is given, it will be used as the random number generator.

R([1,2,3]).sample()    # => 2
R([1,2,3]).sample(2)   # => [3,1]
R([1,2,3]).sample(4)   # => [2,1,3]

- (void) reject_bang(block)

Equivalent to Array#delete_if, deleting elements from self for which the block evaluates to true, but returns nil if no changes were made. The array is changed instantly every time the block is called and not after the iteration is over. See also Enumerable#reject and Array#delete_if.

If no block is given, an enumerator is returned instead.

- (void) replace(val)

Replaces the contents of self with the contents of other_ary, truncating or expanding if necessary.

Examples:

  a = R([ "a", "b", "c", "d", "e" ])
  a.replace([ "x", "y", "z" ])   # => ["x", "y", "z"]
  a                              # => ["x", "y", "z"]
  a.replace(R([1]))             # => [1]

- (void) reverse()

Returns a new array containing self‘s elements in reverse order.

R([ "a", "b", "c" ]).reverse()   #=> ["c", "b", "a"]
R([ 1 ]).reverse()               #=> [1]

- (void) reverse_bang()

Reverses self in place.

a = R([ "a", "b", "c" ])
a.reverse_bang()   #=> ["c", "b", "a"]
a                  #=> ["c", "b", "a"]

- (void) reverse_each(block)

Same as Array#each, but traverses self in reverse order.

a = R([ "a", "b", "c" ])
a.reverse_each (x) -> R.puts "#{x} "
# out: c b a

- (void) rotate(cnt)

Returns new array by rotating self so that the element at cnt in self is the first element of the new array. If cnt is negative then it rotates in the opposite direction.

Examples:

  a = R([ "a", "b", "c", "d" ])
  a.rotate()       # => ["b", "c", "d", "a"]
  a                # => ["a", "b", "c", "d"]
  a.rotate(2)      # => ["c", "d", "a", "b"]
  a.rotate(-3)     # => ["b", "c", "d", "a"]

- (void) rotate_bang(cnt)

Rotates self in place so that the element at cnt comes first, and returns self. If cnt is negative then it rotates in the opposite direction.

a = R([ "a", "b", "c", "d" ])
a.rotate_bang()      # => ["b", "c", "d", "a"]
a                    # => ["b", "c", "d", "a"]
a.rotate_bang(2)     # => ["d", "a", "b", "c"]
a.rotate_bang(-3)    # => ["a", "b", "c", "d"]

- (void) select_bang(block)

Invokes the block passing in successive elements from self, deleting elements for which the block returns a false value. It returns self if changes were made, otherwise it returns nil. See also Array#keep_if

If no block is given, an enumerator is returned instead.

- (void) shift(n)

Returns the first element of self and removes it (shifting all other elements down by one). Returns nil if the array is empty.

If a number n is given, returns an array of the first n elements (or less) just like array.slice!(0, n) does.

args = R([ "-m", "-q", "filename" ])
args.shift()     #=> "-m"
args             #=> ["-q", "filename"]

args = R([ "-m", "-q", "filename" ])
args.shift(2)  #=> ["-m", "-q"]
args           #=> ["filename"]

- (void) shuffle()

Returns a new array with elements of this array shuffled.

a = [ 1, 2, 3 ]           #=> [1, 2, 3]
a.shuffle()                 #=> [2, 3, 1]

- (void) shuffle_bang()

Shuffles elements in self in place. If rng is given, it will be used as the random number generator.

- (void) size()

Length of array

- (void) __size__()

Length of array as literal

- (void) slice(idx, length)

Element Reference—Returns the element at index, or returns a subarray starting at start and continuing for length elements, or returns a subarray specified by range. Negative indices count backward from the end of the array (-1 is the last element). Returns null if the index (or starting index) are out of range.

Examples:

  a = R([ "a", "b", "c", "d", "e" ])
  a.slice(2) +  a[0] + a[1]    #=> "cab"
  a.slice(6)                   #=> null
  a.slice(1, 2)                #=> [ "b", "c" ]
  a.slice(1..3)                #=> [ "b", "c", "d" ]
  a.slice(4..7)                #=> [ "e" ]
  a.slice(6..10)               #=> null
  a.slice(-3, 3)               #=> [ "c", "d", "e" ]
  # special cases
  a.slice(5)                   #=> null
  a.slice(5, 1)                #=> []
  a.slice(5..10)               #=> []

- (void) slice_bang(idx, length)

Deletes the element(s) given by an index (optionally with a length) or by a range. Returns the deleted object (or objects), or null if the index is out of range.

Examples:

  a = R([ "a", "b", "c" ])
  a.slice_bang(1)     # => "b"
  a                   # => ["a", "c"]
  a.slice_bang(-1)    # => "c"
  a                   # => ["a"]
  a.slice_bang(100)   # => null
  a                   # => ["a"]

- (void) sort_bang(block)

Note: Suboptimally implemented, by replacing it with Enumerable#sort().to_native()

Sorts self. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block implements a comparison between a and b, returning -1, 0, or +1.

See also:

  • Enumerable#sort_by

- (void) sort_by_bang(block)

Sorts self in place using a set of keys generated by mapping the values in self through the given block.

If no block is given, an enumerator is returned instead.

- (void) transpose()

Assumes that self is an array of arrays and transposes the rows and columns.

Examples:

  a = R([[1,2], [3,4], [5,6]])
  a.transpose()   # => [[1, 3, 5], [2, 4, 6]]

- (void) uniq()

Note: Not yet correctly implemented. should use #eql on objects, but uses @include().

Returns a new array by removing duplicate values in self.

Examples:

  a = R([ "a", "a", "b", "b", "c" ])
  a.uniq()   # => ["a", "b", "c"]
  # Not yet implemented:
  c = R([ "a:def", "a:xyz", "b:abc", "b:xyz", "c:jkl" ])
  c.uniq (s) -> s[/^\w+/]  #=> [ "a:def", "b:abc", "c:jkl" ]

- (void) uniq_bang(block)

Note: Not yet correctly implemented. should use #eql on objects, but uses @include().

Removes duplicate elements from self. Returns null if no changes are made (that is, no duplicates are found).

Examples:

  a = R([ "a", "a", "b", "b", "c" ])
  a.uniq!   # => ["a", "b", "c"]
  b = R([ "a", "b", "c" ])
  b.uniq!   # => null
  # Not yet implemented:
  c = R([ "a:def", "a:xyz", "b:abc", "b:xyz", "c:jkl" ])
  c.uniq (s) -> s[/^\w+/]  #=> [ "a:def", "b:abc", "c:jkl" ]

- (void) unshift(args...)

Prepends objects to the front of self, moving other elements upwards.

Examples:

  a = R([ "b", "c", "d"])
  a.unshift("a")   #=> ["a", "b", "c", "d"]
  a.unshift(1, 2)  #=> [ 1, 2, "a", "b", "c", "d"]

- (void) union(other)

Set Union—Returns a new array by joining this array with other_ary, removing duplicates.

R([ "a", "b", "c" ]).union [ "c", "d", "a" ]
  #=> [ "a", "b", "c", "d" ]

- (void) to_a()

- (void) to_enum(iter = "each", args...)

find a better way for this.

- (void) to_ary()

- (void) values_at(args...)

TODO: not working with ranges

Returns an array containing the elements in self corresponding to the given selector(s). The selectors may be either integer indices or ranges. See also Array#select.

Examples:

  a = R(['a', 'b', 'c', 'd', 'e', 'f'])
  a.values_at(1, 3, 5)
  a.values_at(1, 3, 5, 7)
  a.values_at(-1, -3, -5, -7)
  a.values_at(1..3, 2...5)

- (void) __native_array_with__(size, obj)