Method: Set#only

Defined in:
lib/autumn/misc.rb

#onlyObject

Returns the only element of a one-element set. Raises an exception if there isn’t exactly one element in the set.

Raises:

  • (IndexError)


83
84
85
86
# File 'lib/autumn/misc.rb', line 83

def only
  raise IndexError, "Set#only called on non-single-element set" unless size == 1
  to_a.first
end