Sha256: a698718aa88362d212c89a1b9c7a7a971050bfef32ef0389d7423c95f493d919
Contents?: true
Size: 408 Bytes
Versions: 7
Compression:
Stored size: 408 Bytes
Contents
class Array # Returns the _only_ element in the array. Raises an IndexError if # the array's size is not 1. # # [5].only # -> 5 # [1,2,3].only # -> IndexError # [].only # -> IndexError # # CREDIT: Gavin Sinclair # CREDIT: Noah Gibbs def only unless size == 1 raise IndexError, "Array#only called on non-single-element array" end first end end
Version data entries
7 entries across 7 versions & 2 rubygems