Sha256: 714550771c70289992fde35291174c49b7eda10d770d7c7b59cf0375615aebb3
Contents?: true
Size: 564 Bytes
Versions: 16
Compression:
Stored size: 564 Bytes
Contents
# encoding: utf-8 class Array # Returns the _only_ element in the array or raise # +IndexError+ if array hasn't exactly one element. # # @author Botanicus # @from Extensions # @since 0.0.3 # @raise [IndexError] If array hasn't exactly one element # @return [Object] First (and only) item of the array # @example # [5].only # => 5 # [1, 2, 3].only # => IndexError # [].only # => IndexError def only raise IndexError, "Array#only called on non-single-element array" unless self.size == 1 self.first end end
Version data entries
16 entries across 16 versions & 4 rubygems