Flowdock
fetch(...) public

Tries to return the element at position index. If the index lies outside the array, the first form throws an IndexError exception, the second form returns default, and the third form returns the value of invoking the block, passing in the index. Negative values of index count from the end of the array.

   a = [ 11, 22, 33, 44 ]
   a.fetch(1)               #=> 22
   a.fetch(-1)              #=> 44
   a.fetch(4, 'cat')        #=> "cat"
   a.fetch(4) { |i| i*i }   #=> 16
Show source
Register or log in to add new notes.
March 11, 2015 - (v1_9_3_392)
0 thanks

equals a.fetch and a.at(1)

a.fetch(1) == a.at(1) #=> true