PATH:
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
U:RDoc::AnyMethod[iI"[]=:ETI"Array#[]=;TF:publico:RDoc::Markup::Document:@parts[7o:RDoc::Markup::Paragraph; [I"OAssigns elements in +self+, based on the given +object+; returns +object+.;To:RDoc::Markup::BlankLine o; ; [I"In brief:;T@o:RDoc::Markup::Verbatim; [I"a_orig = [:foo, 'bar', 2] ;TI" ;TI"# With argument index. ;TI"a = a_orig.dup ;TI"a[0] = 'foo' # => "foo" ;TI"a # => ["foo", "bar", 2] ;TI"a = a_orig.dup ;TI"a[7] = 'foo' # => "foo" ;TI"8a # => [:foo, "bar", 2, nil, nil, nil, nil, "foo"] ;TI" ;TI"(# With arguments start and length. ;TI"a = a_orig.dup ;TI" a[0, 2] = 'foo' # => "foo" ;TI"a # => ["foo", 2] ;TI"a = a_orig.dup ;TI"!a[6, 50] = 'foo' # => "foo" ;TI"3a # => [:foo, "bar", 2, nil, nil, nil, "foo"] ;TI" ;TI"# With argument range. ;TI"a = a_orig.dup ;TI" a[0..1] = 'foo' # => "foo" ;TI"a # => ["foo", 2] ;TI"a = a_orig.dup ;TI"!a[6..50] = 'foo' # => "foo" ;TI"3a # => [:foo, "bar", 2, nil, nil, nil, "foo"] ;T:@format0o; ; [I"VWhen Integer argument +index+ is given, assigns +object+ to an element in +self+.;T@o; ; [I"PIf +index+ is non-negative, assigns +object+ the element at offset +index+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"a[0] = 'foo' # => "foo" ;TI"a # => ["foo", "bar", 2] ;T; 0o; ; [I"HIf +index+ is greater than <tt>self.length</tt>, extends the array:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"a[7] = 'foo' # => "foo" ;TI"8a # => [:foo, "bar", 2, nil, nil, nil, nil, "foo"] ;T; 0o; ; [I"HIf +index+ is negative, counts backwards from the end of the array:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"a[-1] = 'two' # => "two" ;TI"!a # => [:foo, "bar", "two"] ;T; 0o; ; [I"[When Integer arguments +start+ and +length+ are given and +object+ is not an +Array+, ;TI"Gremoves <tt>length - 1</tt> elements beginning at offset +start+, ;TI",and assigns +object+ at offset +start+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI" a[0, 2] = 'foo' # => "foo" ;TI"a # => ["foo", 2] ;T; 0o; ; [I"HIf +start+ is negative, counts backwards from the end of the array:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"!a[-2, 2] = 'foo' # => "foo" ;TI"a # => [:foo, "foo"] ;T; 0o; ; [I"PIf +start+ is non-negative and outside the array (<tt> >= self.size</tt>), ;TI"Gextends the array with +nil+, assigns +object+ at offset +start+, ;TI"and ignores +length+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"!a[6, 50] = 'foo' # => "foo" ;TI"3a # => [:foo, "bar", 2, nil, nil, nil, "foo"] ;T; 0o; ; [I"JIf +length+ is zero, shifts elements at and following offset +start+ ;TI",and assigns +object+ at offset +start+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI" a[1, 0] = 'foo' # => "foo" ;TI"$a # => [:foo, "foo", "bar", 2] ;T; 0o; ; [I"PIf +length+ is too large for the existing array, does not extend the array:;T@o;; [I"a = [:foo, 'bar', 2] ;TI" a[1, 5] = 'foo' # => "foo" ;TI"a # => [:foo, "foo"] ;T; 0o; ; [I"JWhen Range argument +range+ is given and +object+ is not an +Array+, ;TI"Gremoves <tt>length - 1</tt> elements beginning at offset +start+, ;TI",and assigns +object+ at offset +start+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI" a[0..1] = 'foo' # => "foo" ;TI"a # => ["foo", 2] ;T; 0o; ; [I"Uif <tt>range.begin</tt> is negative, counts backwards from the end of the array:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"!a[-2..2] = 'foo' # => "foo" ;TI"a # => [:foo, "foo"] ;T; 0o; ; [I"<If the array length is less than <tt>range.begin</tt>, ;TI"Textends the array with +nil+, assigns +object+ at offset <tt>range.begin</tt>, ;TI"and ignores +length+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"!a[6..50] = 'foo' # => "foo" ;TI"3a # => [:foo, "bar", 2, nil, nil, nil, "foo"] ;T; 0o; ; [I"TIf <tt>range.end</tt> is zero, shifts elements at and following offset +start+ ;TI",and assigns +object+ at offset +start+:;T@o;; [I"a = [:foo, 'bar', 2] ;TI" a[1..0] = 'foo' # => "foo" ;TI"$a # => [:foo, "foo", "bar", 2] ;T; 0o; ; [I"LIf <tt>range.end</tt> is negative, assigns +object+ at offset +start+, ;TI"Tretains <tt>range.end.abs -1</tt> elements past that, and removes those beyond:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"!a[1..-1] = 'foo' # => "foo" ;TI"a # => [:foo, "foo"] ;TI"a = [:foo, 'bar', 2] ;TI"!a[1..-2] = 'foo' # => "foo" ;TI"a # => [:foo, "foo", 2] ;TI"a = [:foo, 'bar', 2] ;TI"!a[1..-3] = 'foo' # => "foo" ;TI"$a # => [:foo, "foo", "bar", 2] ;TI"a = [:foo, 'bar', 2] ;T; 0o; ; [I"@If <tt>range.end</tt> is too large for the existing array, ;TI"Nreplaces array elements, but does not extend the array with +nil+ values:;T@o;; [I"a = [:foo, 'bar', 2] ;TI" a[1..5] = 'foo' # => "foo" ;TI"a # => [:foo, "foo"] ;T; 0o; ; [I"PRelated: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning].;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"jself[index] = object -> object self[start, length] = object -> object self[range] = object -> object ;T0[ I"(*args);T@�FI" Array;TcRDoc::NormalClass00
[+]
..
[-] assoc-i.ri
[edit]
[-] %2d-i.ri
[edit]
[-] bsearch_index-i.ri
[edit]
[-] collect-i.ri
[edit]
[-] last-i.ri
[edit]
[-] include%3f-i.ri
[edit]
[-] count-i.ri
[edit]
[-] size-i.ri
[edit]
[-] bsearch-i.ri
[edit]
[-] %7c-i.ri
[edit]
[-] all%3f-i.ri
[edit]
[-] try_convert-c.ri
[edit]
[-] %3c%3c-i.ri
[edit]
[-] to_s-i.ri
[edit]
[-] delete-i.ri
[edit]
[-] flatten%21-i.ri
[edit]
[-] max-i.ri
[edit]
[-] uniq%21-i.ri
[edit]
[-] %2a-i.ri
[edit]
[-] push-i.ri
[edit]
[-] pop-i.ri
[edit]
[-] transpose-i.ri
[edit]
[-] initialize_copy-i.ri
[edit]
[-] first-i.ri
[edit]
[-] any%3f-i.ri
[edit]
[-] %3c%3d%3e-i.ri
[edit]
[-] %5b%5d%3d-i.ri
[edit]
[-] prepend-i.ri
[edit]
[-] reverse_each-i.ri
[edit]
[-] collect%21-i.ri
[edit]
[-] each_index-i.ri
[edit]
[-] sort-i.ri
[edit]
[-] shuffle-i.ri
[edit]
[-] to_a-i.ri
[edit]
[-] union-i.ri
[edit]
[-] flatten-i.ri
[edit]
[-] %26-i.ri
[edit]
[-] filter-i.ri
[edit]
[-] shelljoin-i.ri
[edit]
[-] new-c.ri
[edit]
[-] reject%21-i.ri
[edit]
[-] reverse%21-i.ri
[edit]
[-] minmax-i.ri
[edit]
[-] difference-i.ri
[edit]
[-] sample-i.ri
[edit]
[-] fetch_values-i.ri
[edit]
[-] fill-i.ri
[edit]
[-] reverse-i.ri
[edit]
[-] find_index-i.ri
[edit]
[-] rotate-i.ri
[edit]
[-] fetch-i.ri
[edit]
[-] sum-i.ri
[edit]
[-] join-i.ri
[edit]
[-] min-i.ri
[edit]
[-] to_h-i.ri
[edit]
[-] to_ary-i.ri
[edit]
[-] take_while-i.ri
[edit]
[-] repeated_permutation-i.ri
[edit]
[-] hash-i.ri
[edit]
[-] one%3f-i.ri
[edit]
[-] values_at-i.ri
[edit]
[-] uniq-i.ri
[edit]
[-] product-i.ri
[edit]
[-] each-i.ri
[edit]
[-] permutation-i.ri
[edit]
[-] eql%3f-i.ri
[edit]
[-] intersect%3f-i.ri
[edit]
[-] slice-i.ri
[edit]
[-] append-i.ri
[edit]
[-] sort%21-i.ri
[edit]
[-] empty%3f-i.ri
[edit]
[-] slice%21-i.ri
[edit]
[-] keep_if-i.ri
[edit]
[-] map-i.ri
[edit]
[-] intersection-i.ri
[edit]
[-] repeated_combination-i.ri
[edit]
[-] sort_by%21-i.ri
[edit]
[-] combination-i.ri
[edit]
[-] insert-i.ri
[edit]
[-] map%21-i.ri
[edit]
[-] zip-i.ri
[edit]
[-] drop-i.ri
[edit]
[-] %5b%5d-i.ri
[edit]
[-] shuffle%21-i.ri
[edit]
[-] at-i.ri
[edit]
[-] reject-i.ri
[edit]
[-] shift-i.ri
[edit]
[-] filter%21-i.ri
[edit]
[-] compact-i.ri
[edit]
[-] rassoc-i.ri
[edit]
[-] freeze-i.ri
[edit]
[-] %2b-i.ri
[edit]
[-] drop_while-i.ri
[edit]
[-] take-i.ri
[edit]
[-] dig-i.ri
[edit]
[-] select-i.ri
[edit]
[-] cdesc-Array.ri
[edit]
[-] cycle-i.ri
[edit]
[-] %3d%3d-i.ri
[edit]
[-] rotate%21-i.ri
[edit]
[-] index-i.ri
[edit]
[-] rindex-i.ri
[edit]
[-] pack-i.ri
[edit]
[-] inspect-i.ri
[edit]
[-] select%21-i.ri
[edit]
[-] replace-i.ri
[edit]
[-] %5b%5d-c.ri
[edit]
[-] none%3f-i.ri
[edit]
[-] clear-i.ri
[edit]
[-] length-i.ri
[edit]
[-] concat-i.ri
[edit]
[-] unshift-i.ri
[edit]
[-] delete_at-i.ri
[edit]
[-] delete_if-i.ri
[edit]
[-] compact%21-i.ri
[edit]