Class: FutureProof::FutureArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Exceptionable
Defined in:
lib/future_proof/future_array.rb

Overview

FutureArray should be used to raise exceptions if specific values are exception instances on a direct access with #[], #first, #last, #each, #sort and so on.

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ FutureArray

Returns a new instance of FutureArray.



10
11
12
# File 'lib/future_proof/future_array.rb', line 10

def initialize(arg)
  @arry = Array.new arg
end

Instance Method Details

#[](index) ⇒ Object

Acces FutureArray value by index.



15
16
17
# File 'lib/future_proof/future_array.rb', line 15

def [](index)
  raise_or_value @arry[index]
end

#allObject

Note:

raises an exception if any value if an exception.

Array of values.



22
23
24
# File 'lib/future_proof/future_array.rb', line 22

def all
  map { |a| a }
end

#eachObject

Note:

raises an error if any value is an exception.

Iterates through array elements.



35
36
37
# File 'lib/future_proof/future_array.rb', line 35

def each
  @arry.each { |a| yield raise_or_value(a) }
end