Class: Array
- Object
- Array
encoding: utf-8
Public Visibility
Public Instance Method Summary
#only |
Returns the only element in the array or raise IndexError if array hasn’t exactly one element. Returns: Object |
---|---|
#rand #random |
Returns random item from the array. Returns: Object |
Public Instance Methods Inherited from Object
Public Instance Method Details
only
Returns the only element in the array or raise IndexError if array hasn’t exactly one element.
[View source]
16 17 18 19 |
# File 'lib/rango/ext/array.rb', line 16 def only raise IndexError, "Array#only called on non-single-element array" unless self.size == 1 self.first end |
rand
Also known as: random
Returns random item from the array
[View source]
9 10 11 |
# File 'lib/rango/ext/random.rb', line 9 def rand self[Kernel.rand(length)] end |