This is a Ruby tree! It shows every object from the Ruby Programming Language in a tree format.
# Array.[] (from ruby core) --- [](*args) --- Returns a new array populated with the given objects. Array.[]( 1, 'a', /^A/) # => [1, "a", /^A/] Array[ 1, 'a', /^A/ ] # => [1, "a", /^A/] [ 1, 'a', /^A/ ] # => [1, "a", /^A/] (from ruby core) --- array[index] -> object or nil array[start, length] -> object or nil array[range] -> object or nil array[aseq] -> object or nil array.slice(index) -> object or nil array.slice(start, length) -> object or nil array.slice(range) -> object or nil array.slice(aseq) -> object or nil --- Returns elements from `self`; does not modify `self`. When a single Integer argument `index` is given, returns the element at offset `index`: a = [:foo, 'bar', 2] a[0] # => :foo a[2] # => 2 a # => [:foo, "bar", 2] If `index` is negative, counts relative to the end of `self`: a = [:foo, 'bar', 2] a[-1] # => 2 a[-2] # => "bar" If `index` is out of range, returns `nil`. When two Integer arguments `start` and `length` are given, returns a new Array of size `length` containing successive elements beginning at offset `start`: a = [:foo, 'bar', 2] a[0, 2] # => [:foo, "bar"] a[1, 2] # => ["bar", 2] If `start + length` is greater than `self.length`, returns all elements from offset `start` to the end: a = [:foo, 'bar', 2] a[0, 4] # => [:foo, "bar", 2] a[1, 3] # => ["bar", 2] a[2, 2] # => [2] If `start == self.size` and `length >= 0`, returns a new empty Array. If `length` is negative, returns `nil`. When a single Range argument `range` is given, treats `range.min` as `start` above and `range.size` as `length` above: a = [:foo, 'bar', 2] a[0..1] # => [:foo, "bar"] a[1..2] # => ["bar", 2] Special case: If `range.start == a.size`, returns a new empty Array. If `range.end` is negative, calculates the end index from the end: a = [:foo, 'bar', 2] a[0..-1] # => [:foo, "bar", 2] a[0..-2] # => [:foo, "bar"] a[0..-3] # => [:foo] If `range.start` is negative, calculates the start index from the end: a = [:foo, 'bar', 2] a[-1..2] # => [2] a[-2..2] # => ["bar", 2] a[-3..2] # => [:foo, "bar", 2] If `range.start` is larger than the array size, returns `nil`. a = [:foo, 'bar', 2] a[4..1] # => nil a[4..0] # => nil a[4..-1] # => nil When a single Enumerator::ArithmeticSequence argument `aseq` is given, returns an Array of elements corresponding to the indexes produced by the sequence. a = ['--', 'data1', '--', 'data2', '--', 'data3'] a[(1..).step(2)] # => ["data1", "data2", "data3"] Unlike slicing with range, if the start or the end of the arithmetic sequence is larger than array size, throws RangeError. a = ['--', 'data1', '--', 'data2', '--', 'data3'] a[(1..11).step(2)] # RangeError (((1..11).step(2)) out of range) a[(7..).step(2)] # RangeError (((7..).step(2)) out of range) If given a single argument, and its type is not one of the listed, tries to convert it to Integer, and raises if it is impossible: a = [:foo, 'bar', 2] # Raises TypeError (no implicit conversion of Symbol into Integer): a[:foo] Array#slice is an alias for Array#[].
This is MURDOC! A Ruby documentation browser inspired by Smalltalk-80. It allows you to learn about Ruby by browsing through its class hierarchies, and see any of its methods.