Class: Array
Direct Known Subclasses
Instance Method Summary collapse
-
#only ⇒ Object
Returns the only element in the array or raise
IndexError
if array hasn’t exactly one element. -
#rand ⇒ Object
(also: #random)
Returns random item from the array.
Instance Method Details
#only ⇒ Object
Returns the only element in the array or raise IndexError
if array hasn’t exactly one element.
16 17 18 19 |
# File 'lib/rubyexts/array.rb', line 16 def only raise IndexError, "Array#only called on non-single-element array" unless self.size == 1 self.first end |