Method: Functional::Tuple#fetch
- Defined in:
- lib/functional/tuple.rb
#fetch(index, default) ⇒ Object
Retrieve the item at the given index or return the given default value if the index is out of bounds. The behavior of indicies follows the rules for the ‘at` method.
68 69 70 71 72 73 74 |
# File 'lib/functional/tuple.rb', line 68 def fetch(index, default) if index >= length || -index > length default else at(index) end end |