D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
fetch-i.ri
back
Copy
U:RDoc::AnyMethod[iI" fetch:ETI"Array#fetch;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"`Returns the element of +self+ at offset +index+ if +index+ is in range; +index+ must be an ;TI"a{integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects].;To:RDoc::Markup::BlankLine o; ; [I"4With the single argument +index+ and no block, ;TI"+returns the element at offset +index+:;T@o:RDoc::Markup::Verbatim; [I"a = [:foo, 'bar', 2] ;TI"a.fetch(1) # => "bar" ;TI"a.fetch(1.1) # => "bar" ;T:@format0o; ; [I">If +index+ is negative, counts from the end of the array:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"a.fetch(-1) # => 2 ;TI"a.fetch(-2) # => "bar" ;T; 0o; ; [I"XWith arguments +index+ and +default_value+ (which may be any object) and no block, ;TI"8returns +default_value+ if +index+ is out-of-range:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"!a.fetch(1, nil) # => "bar" ;TI" a.fetch(3, :foo) # => :foo ;T; 0o; ; [I"(With argument +index+ and a block, ;TI"@returns the element at offset +index+ if index is in range ;TI"f(and the block is not called); otherwise calls the block with index and returns its return value:;T@o;; [I"a = [:foo, 'bar', 2] ;TI"<a.fetch(1) {|index| raise 'Cannot happen' } # => "bar" ;TI"Ea.fetch(50) {|index| "Value for #{index}" } # => "Value for 50" ;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"�fetch(index) -> element fetch(index, default_value) -> element or default_value fetch(index) {|index| ... } -> element or block_return_value ;T0[ I"(p1, p2 = v2);T@7FI" Array;TcRDoc::NormalClass00