D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
fill-i.ri
back
Copy
U:RDoc::AnyMethod[iI" fill:ETI"Array#fill;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"+Replaces selected elements in +self+; ;TI"!may add elements to +self+; ;TI"/always returns +self+ (never a new array).;To:RDoc::Markup::BlankLine o; ; [I"In brief:;T@o:RDoc::Markup::Verbatim; [I"# Non-negative start. ;TI"M['a', 'b', 'c', 'd'].fill('-', 1, 2) # => ["a", "-", "-", "d"] ;TI"M['a', 'b', 'c', 'd'].fill(1, 2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;TI" ;TI"3# Extends with specified values if necessary. ;TI"R['a', 'b', 'c', 'd'].fill('-', 3, 2) # => ["a", "b", "c", "-", "-"] ;TI"R['a', 'b', 'c', 'd'].fill(3, 2) {|e| e.to_s } # => ["a", "b", "c", "3", "4"] ;TI" ;TI"%# Fills with nils if necessary. ;TI"a['a', 'b', 'c', 'd'].fill('-', 6, 2) # => ["a", "b", "c", "d", nil, nil, "-", "-"] ;TI"a['a', 'b', 'c', 'd'].fill(6, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, nil, "6", "7"] ;TI" ;TI":# For negative start, counts backwards from the end. ;TI"N['a', 'b', 'c', 'd'].fill('-', -3, 3) # => ["a", "-", "-", "-"] ;TI"N['a', 'b', 'c', 'd'].fill(-3, 3) {|e| e.to_s } # => ["a", "1", "2", "3"] ;TI" ;TI"# Range. ;TI"M['a', 'b', 'c', 'd'].fill('-', 1..2) # => ["a", "-", "-", "d"] ;TI"M['a', 'b', 'c', 'd'].fill(1..2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;T:@format0o; ; [ I"3When arguments +start+ and +count+ are given, ;TI"8they select the elements of +self+ to be replaced; ;TI"each must be an ;TI"a{integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects] ;TI"(or +nil+):;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"R+start+ specifies the zero-based offset of the first element to be replaced; ;TI"+nil+ means zero.;To;;0; [o; ; [I"C+count+ is the number of consecutive elements to be replaced; ;TI" +nil+ means "all the rest.";T@o; ; [I"#With argument +object+ given, ;TI"2that one object is used for all replacements:;T@o;; [ I"@o = Object.new # => #<Object:0x0000014e7bff7600> ;TI"8a = ['a', 'b', 'c', 'd'] # => ["a", "b", "c", "d"] ;TI"a.fill(o, 1, 2) ;TI"Q# => ["a", #<Object:0x0000014e7bff7600>, #<Object:0x0000014e7bff7600>, "d"] ;T; 0o; ; [ I"SWith a block given, the block is called once for each element to be replaced; ;TI"Pthe value passed to the block is the _index_ of the element to be replaced ;TI"(not the element itself); ;TI"3the block's return value replaces the element:;T@o;; [I"Fa = ['a', 'b', 'c', 'd'] # => ["a", "b", "c", "d"] ;TI"Fa.fill(1, 2) {|element| element.to_s } # => ["a", "1", "2", "d"] ;T; 0o; ; [I"'For arguments +start+ and +count+:;T@o;;;;[o;;0; [o; ; [I"!If +start+ is non-negative, ;TI";replaces +count+ elements beginning at offset +start+:;T@o;; [I"D['a', 'b', 'c', 'd'].fill('-', 0, 2) # => ["-", "-", "c", "d"] ;TI"D['a', 'b', 'c', 'd'].fill('-', 1, 2) # => ["a", "-", "-", "d"] ;TI"D['a', 'b', 'c', 'd'].fill('-', 2, 2) # => ["a", "b", "-", "-"] ;TI" ;TI"M['a', 'b', 'c', 'd'].fill(0, 2) {|e| e.to_s } # => ["0", "1", "c", "d"] ;TI"M['a', 'b', 'c', 'd'].fill(1, 2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;TI"M['a', 'b', 'c', 'd'].fill(2, 2) {|e| e.to_s } # => ["a", "b", "2", "3"] ;T; 0o; ; [I"!Extends +self+ if necessary:;T@o;; [ I"I['a', 'b', 'c', 'd'].fill('-', 3, 2) # => ["a", "b", "c", "-", "-"] ;TI"N['a', 'b', 'c', 'd'].fill('-', 4, 2) # => ["a", "b", "c", "d", "-", "-"] ;TI" ;TI"R['a', 'b', 'c', 'd'].fill(3, 2) {|e| e.to_s } # => ["a", "b", "c", "3", "4"] ;TI"W['a', 'b', 'c', 'd'].fill(4, 2) {|e| e.to_s } # => ["a", "b", "c", "d", "4", "5"] ;T; 0o; ; [I"#Fills with +nil+ if necessary:;T@o;; [ I"S['a', 'b', 'c', 'd'].fill('-', 5, 2) # => ["a", "b", "c", "d", nil, "-", "-"] ;TI"X['a', 'b', 'c', 'd'].fill('-', 6, 2) # => ["a", "b", "c", "d", nil, nil, "-", "-"] ;TI" ;TI"\['a', 'b', 'c', 'd'].fill(5, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, "5", "6"] ;TI"a['a', 'b', 'c', 'd'].fill(6, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, nil, "6", "7"] ;T; 0o; ; [I"-Does nothing if +count+ is non-positive:;T@o;; [I"G['a', 'b', 'c', 'd'].fill('-', 2, 0) # => ["a", "b", "c", "d"] ;TI"G['a', 'b', 'c', 'd'].fill('-', 2, -100) # => ["a", "b", "c", "d"] ;TI"G['a', 'b', 'c', 'd'].fill('-', 6, -100) # => ["a", "b", "c", "d"] ;TI" ;TI"^['a', 'b', 'c', 'd'].fill(2, 0) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ;TI"^['a', 'b', 'c', 'd'].fill(2, -100) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ;TI"^['a', 'b', 'c', 'd'].fill(6, -100) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ;T; 0o;;0; [o; ; [I"EIf +start+ is negative, counts backwards from the end of +self+:;T@o;; [ I"E['a', 'b', 'c', 'd'].fill('-', -4, 3) # => ["-", "-", "-", "d"] ;TI"E['a', 'b', 'c', 'd'].fill('-', -3, 3) # => ["a", "-", "-", "-"] ;TI" ;TI"N['a', 'b', 'c', 'd'].fill(-4, 3) {|e| e.to_s } # => ["0", "1", "2", "d"] ;TI"N['a', 'b', 'c', 'd'].fill(-3, 3) {|e| e.to_s } # => ["a", "1", "2", "3"] ;T; 0o; ; [I"!Extends +self+ if necessary:;T@o;; [ I"J['a', 'b', 'c', 'd'].fill('-', -2, 3) # => ["a", "b", "-", "-", "-"] ;TI"O['a', 'b', 'c', 'd'].fill('-', -1, 3) # => ["a", "b", "c", "-", "-", "-"] ;TI" ;TI"S['a', 'b', 'c', 'd'].fill(-2, 3) {|e| e.to_s } # => ["a", "b", "2", "3", "4"] ;TI"X['a', 'b', 'c', 'd'].fill(-1, 3) {|e| e.to_s } # => ["a", "b", "c", "3", "4", "5"] ;T; 0o; ; [I"OStarts at the beginning of +self+ if +start+ is negative and out-of-range:;T@o;; [ I"E['a', 'b', 'c', 'd'].fill('-', -5, 2) # => ["-", "-", "c", "d"] ;TI"E['a', 'b', 'c', 'd'].fill('-', -6, 2) # => ["-", "-", "c", "d"] ;TI" ;TI"N['a', 'b', 'c', 'd'].fill(-5, 2) {|e| e.to_s } # => ["0", "1", "c", "d"] ;TI"N['a', 'b', 'c', 'd'].fill(-6, 2) {|e| e.to_s } # => ["0", "1", "c", "d"] ;T; 0o; ; [I"-Does nothing if +count+ is non-positive:;T@o;; [ I"F['a', 'b', 'c', 'd'].fill('-', -2, 0) # => ["a", "b", "c", "d"] ;TI"F['a', 'b', 'c', 'd'].fill('-', -2, -1) # => ["a", "b", "c", "d"] ;TI" ;TI"]['a', 'b', 'c', 'd'].fill(-2, 0) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ;TI"]['a', 'b', 'c', 'd'].fill(-2, -1) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ;T; 0o; ; [ I"%When argument +range+ is given, ;TI":it must be a Range object whose members are numeric; ;TI"Cits +begin+ and +end+ values determine the elements of +self+ ;TI"to be replaced:;T@o;;;;[ o;;0; [o; ; [I"VIf both +begin+ and +end+ are positive, they specify the first and last elements ;TI"to be replaced:;T@o;; [I"M['a', 'b', 'c', 'd'].fill('-', 1..2) # => ["a", "-", "-", "d"] ;TI"M['a', 'b', 'c', 'd'].fill(1..2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;T; 0o; ; [I"<If +end+ is smaller than +begin+, replaces no elements:;T@o;; [I"M['a', 'b', 'c', 'd'].fill('-', 2..1) # => ["a", "b", "c", "d"] ;TI"M['a', 'b', 'c', 'd'].fill(2..1) {|e| e.to_s } # => ["a", "b", "c", "d"] ;T; 0o;;0; [o; ; [I"[If either is negative (or both are negative), counts backwards from the end of +self+:;T@o;; [I"F['a', 'b', 'c', 'd'].fill('-', -3..2) # => ["a", "-", "-", "d"] ;TI"F['a', 'b', 'c', 'd'].fill('-', 1..-2) # => ["a", "-", "-", "d"] ;TI"F['a', 'b', 'c', 'd'].fill('-', -3..-2) # => ["a", "-", "-", "d"] ;TI" ;TI"O['a', 'b', 'c', 'd'].fill(-3..2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;TI"O['a', 'b', 'c', 'd'].fill(1..-2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;TI"O['a', 'b', 'c', 'd'].fill(-3..-2) {|e| e.to_s } # => ["a", "1", "2", "d"] ;T; 0o;;0; [o; ; [I"YIf the +end+ value is excluded (see Range#exclude_end?), omits the last replacement:;T@o;; [ I"F['a', 'b', 'c', 'd'].fill('-', 1...2) # => ["a", "-", "c", "d"] ;TI"F['a', 'b', 'c', 'd'].fill('-', 1...-2) # => ["a", "-", "c", "d"] ;TI" ;TI"O['a', 'b', 'c', 'd'].fill(1...2) {|e| e.to_s } # => ["a", "1", "c", "d"] ;TI"O['a', 'b', 'c', 'd'].fill(1...-2) {|e| e.to_s } # => ["a", "1", "c", "d"] ;T; 0o;;0; [o; ; [I"TIf the range is endless (see {Endless Ranges}[rdoc-ref:Range@Endless+Ranges]), ;TI",replaces elements to the end of +self+:;T@o;; [I"L['a', 'b', 'c', 'd'].fill('-', 1..) # => ["a", "-", "-", "-"] ;TI"L['a', 'b', 'c', 'd'].fill(1..) {|e| e.to_s } # => ["a", "1", "2", "3"] ;T; 0o;;0; [o; ; [I"ZIf the range is beginless (see {Beginless Ranges}[rdoc-ref:Range@Beginless+Ranges]), ;TI"4replaces elements from the beginning of +self+:;T@o;; [I"L['a', 'b', 'c', 'd'].fill('-', ..2) # => ["-", "-", "-", "d"] ;TI"L['a', 'b', 'c', 'd'].fill(..2) {|e| e.to_s } # => ["0", "1", "2", "d"] ;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"�fill(object, start = nil, count = nil) -> new_array fill(object, range) -> new_array fill(start = nil, count = nil) {|element| ... } -> new_array fill(range) {|element| ... } -> new_array ;T0[ I"(p1 = v1, p2 = v2);T@�FI" Array;TcRDoc::NormalClass00