D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
values_at-i.ri
back
Copy
U:RDoc::AnyMethod[iI"values_at:ETI"Array#values_at;TF:publico:RDoc::Markup::Document:@parts["o:RDoc::Markup::Paragraph; [I"IReturns elements from +self+ in a new array; does not modify +self+.;To:RDoc::Markup::BlankLine o; ; [I"KThe objects included in the returned array are the elements of +self+ ;TI")selected by the given +specifiers+, ;TI"6each of which must be a numeric index or a Range.;T@o; ; [I"In brief:;T@o:RDoc::Markup::Verbatim; [I"a = ['a', 'b', 'c', 'd'] ;TI" ;TI"# Index specifiers. ;TI"Ia.values_at(2, 0, 2, 0) # => ["c", "a", "c", "a"] # May repeat. ;TI"[a.values_at(-4, -3, -2, -1) # => ["a", "b", "c", "d"] # Counts backwards if negative. ;TI"Na.values_at(-50, 50) # => [nil, nil] # Outside of self. ;TI" ;TI"# Range specifiers. ;TI"Sa.values_at(1..3) # => ["b", "c", "d"] # From range.begin to range.end. ;TI"Ba.values_at(1...3) # => ["b", "c"] # End excluded. ;TI"Fa.values_at(3..1) # => [] # No such elements. ;TI" ;TI"[a.values_at(-3..3) # => ["b", "c", "d"] # Negative range.begin counts backwards. ;TI"Ga.values_at(-50..3) # Raises RangeError. ;TI" ;TI"Ya.values_at(1..-2) # => ["b", "c"] # Negative range.end counts backwards. ;TI"Fa.values_at(1..-50) # => [] # No such elements. ;TI" ;TI"# Mixture of specifiers. ;TI"Ga.values_at(2..3, 3, 0..1, 0) # => ["c", "d", "d", "a", "b", "a"] ;T:@format0o; ; [I";With no +specifiers+ given, returns a new empty array:;T@o;; [I"a = ['a', 'b', 'c', 'd'] ;TI"a.values_at # => [] ;T; 0o; ; [I"=For each numeric specifier +index+, includes an element:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"fFor each non-negative numeric specifier +index+ that is in-range (less than <tt>self.size</tt>), ;TI",includes the element at offset +index+:;T@o;; [I"+a.values_at(0, 2) # => ["a", "c"] ;TI"+a.values_at(0.1, 2.9) # => ["a", "c"] ;T; 0o;;0; [o; ; [I"iFor each negative numeric +index+ that is in-range (greater than or equal to <tt>- self.size</tt>), ;TI"-counts backwards from the end of +self+:;T@o;; [I")a.values_at(-1, -4) # => ["d", "a"] ;T; 0o; ; [I";The given indexes may be in any order, and may repeat:;T@o;; [I"?a.values_at(2, 0, 1, 0, 2) # => ["c", "a", "b", "a", "c"] ;T; 0o; ; [I";For each +index+ that is out-of-range, includes +nil+:;T@o;; [I"(a.values_at(4, -5) # => [nil, nil] ;T; 0o; ; [I"9For each Range specifier +range+, includes elements ;TI">according to <tt>range.begin</tt> and <tt>range.end</tt>:;T@o;;;;[o;;0; [o; ; [ I"9If both <tt>range.begin</tt> and <tt>range.end</tt> ;TI"Care non-negative and in-range (less than <tt>self.size</tt>), ;TI"7includes elements from index <tt>range.begin</tt> ;TI"Fthrough <tt>range.end - 1</tt> (if <tt>range.exclude_end?</tt>), ;TI"/or through <tt>range.end</tt> (otherwise):;T@o;; [I"(a.values_at(1..2) # => ["b", "c"] ;TI"#a.values_at(1...2) # => ["b"] ;T; 0o;;0; [o; ; [I"gIf <tt>range.begin</tt> is negative and in-range (greater than or equal to <tt>- self.size</tt>), ;TI"-counts backwards from the end of +self+:;T@o;; [I"(a.values_at(-2..3) # => ["c", "d"] ;T; 0o;;0; [o; ; [I"OIf <tt>range.begin</tt> is negative and out-of-range, raises an exception:;T@o;; [I"-a.values_at(-5..3) # Raises RangeError. ;T; 0o;;0; [o; ; [I"9If <tt>range.end</tt> is positive and out-of-range, ;TI"4extends the returned array with +nil+ elements:;T@o;; [I"6a.values_at(1..5) # => ["b", "c", "d", nil, nil] ;T; 0o;;0; [o; ; [I"5If <tt>range.end</tt> is negative and in-range, ;TI"-counts backwards from the end of +self+:;T@o;; [I"(a.values_at(1..-2) # => ["b", "c"] ;T; 0o;;0; [o; ; [I"9If <tt>range.end</tt> is negative and out-of-range, ;TI"returns an empty array:;T@o;; [I" a.values_at(1..-5) # => [] ;T; 0o; ; [I"9The given ranges may be in any order and may repeat:;T@o;; [I"Ga.values_at(2..3, 0..1, 2..3) # => ["c", "d", "a", "b", "c", "d"] ;T; 0o; ; [I"CThe given specifiers may be any mixture of indexes and ranges:;T@o;; [I"Ga.values_at(3, 1..2, 0, 2..3) # => ["d", "b", "c", "a", "c", "d"] ;T; 0o; ; [I"NRelated: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I")values_at(*specifiers) -> new_array ;T0[ I"(*args);T@�FI" Array;TcRDoc::NormalClass00