Class: Set
- Inherits:
-
Object
- Object
- Set
- Defined in:
- lib/autumn/misc.rb
Overview
Adds the only method to Set.
Instance Method Summary collapse
-
#only ⇒ Object
Returns the only element of a one-element set.
Instance Method Details
#only ⇒ Object
Returns the only element of a one-element set. Raises an exception if there isn’t exactly one element in the set.
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 |