Class: 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

define_instance_method, not_nil?, try

Public Instance Method Details

only

public Object only

Returns the only element in the array or raise IndexError if array hasn’t exactly one element.

Meta Tags

Parameters:

Returns:

[Object]

First (and only) item of the array

Raises:

[IndexError]

If array hasn’t exactly one element

Author:

Botanicus

Since:

0.0.3

[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

public Object rand

Also known as: random

Returns random item from the array

Meta Tags

Parameters:

Returns:

[Object]

Random item from array

Author:

Botanicus

Since:

0.0.2

[View source]


9
10
11
# File 'lib/rango/ext/random.rb', line 9

def rand
  self[Kernel.rand(length)]
end