Class: Set

Inherits:
Object
  • Object
show all
Defined in:
lib/autumn/misc.rb

Overview

Adds the only method to Set.

Instance Method Summary collapse

Instance Method Details

#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