Method: Immutable::SortedSet#fetch
- Defined in:
- lib/immutable/sorted_set.rb
#fetch(index) ⇒ Object #fetch(index) {|index| ... } ⇒ Object #fetch(index, default) ⇒ Object
Retrieve the value at index with optional default.
254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/immutable/sorted_set.rb', line 254 def fetch(index, default = (missing_default = true)) if index >= -@node.size && index < @node.size at(index) elsif block_given? yield(index) elsif !missing_default default else raise IndexError, "index #{index} outside of sorted set bounds" end end |